473,794 Members | 2,708 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pointers to elements in a Linked-List?

I have a Linked-List and would like to create pointers to elements in this
list.

e.g I would like two pointers that point to each of their elements in the
Linked-List. But there should always be exactly 5 nodes between these
pointers.

Does this make any sense or are there some more efficient way to access
certain elements in a Linked-List?
Nov 15 '05 #1
2 1495


Paminu wrote On 10/12/05 15:26,:
I have a Linked-List and would like to create pointers to elements in this
list.

e.g I would like two pointers that point to each of their elements in the
Linked-List. But there should always be exactly 5 nodes between these
pointers.

Does this make any sense or are there some more efficient way to access
certain elements in a Linked-List?


First: This isn't a C question. It might be a data
structure or algorithm question, in which case comp.programmin g
would be a better forum.

Second: The question isn't well-posed. No arrangement
of data is more or less efficient than any other until you
consider the operations that are to be performed. What are
you planning to do, and why do you expect these extra pointers
to be helpful? (Please *don't* answer: Your question still
isn't about C and doesn't belong here; my point is to show
you that even if you find an appropriate forum your question
as it stands is not a good one.)

Third: Google for "search tree" and/or "skip list."

--
Er*********@sun .com

Nov 15 '05 #2
"Eric Sosman" <er*********@su n.com> wrote in message
news:di******** **@news1brm.Cen tral.Sun.COM...


Paminu wrote On 10/12/05 15:26,:
I have a Linked-List and would like to create pointers to elements in this list.

e.g I would like two pointers that point to each of their elements in the Linked-List. But there should always be exactly 5 nodes between these pointers.

Does this make any sense or are there some more efficient way to access certain elements in a Linked-List?


First: This isn't a C question. It might be a data
structure or algorithm question, in which case comp.programmin g
would be a better forum.


It's an interview question I was once asked. "How do you find the
fifth-from-last item in a singly-linked list?" Why they always choose 5,
I don't know.

You can always tell homework and interview questions by the artificial
contraints on the problem. I mean, why isn't it a doubly-linked list if
they need to go backwards? Why not use a array and jump to the correct
offset?

--
Mabden
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

388
21937
by: maniac | last post by:
Hey guys, I'm new here, just a simple question. I'm learning to Program in C, and I was recommended a book called, "Mastering C Pointers", just asking if any of you have read it, and if it's worth the $25USD. I'm just looking for a book on Pointers, because from what I've read it's one of the toughest topics to understand. thanks in advanced.
23
3218
by: Ken Turkowski | last post by:
The construct (void*)(((long)ptr + 3) & ~3) worked well until now to enforce alignment of the pointer to long boundaries. However, now VC++ warns about it, undoubtedly to help things work on 64 bit machines, i.e. with 64 bit pointers. In the early days of C, where there were problems with the size of int being 16 or 32 bits, the response was that an int was guaranteed to hold a pointer (yes, there were 64Kb address spaces at one time!)....
3
3457
by: ozbear | last post by:
This is probably an obvious question. I know that pointer comparisons are only defined if the two pointers point somewhere "into" the storage allocated to the same object, or if they are NULL, or one-past the end of the object as long as it isn't dereferenced. I use "object" in the standard 'C' sense. Is there some special dispensation given to comparing two pointers
47
2665
by: sunglo | last post by:
Some time a go, in a discussion here in comp.lang.c, I learnt that it's better not to use a (sometype **) where a (void **) is expected (using a cast). Part of the discussion boiled down to the rule: if I cast a (sometype **) to a (void **) I am making a number of assumptions about the implementation's (void **) representation and length. Specifically, if I do the above cast I'm assuming that a (sometype **) and a (void **) have the same...
1
1713
by: ballpointpenthief | last post by:
I am trying to build a generic type for data structures in order to be able to build complex data structures based on other, simpler data structures. So, say we have linked lists, doubly linked lists, and hash tables as some of our elements, we could build up combinations of these and encapsulate them, and then combine these new types to form a new type which could be extended further. ***One way might be to hold a structure-type...
6
2944
by: ivan.leben | last post by:
I want to write a Mesh class using half-edges. This class uses three other classes: Vertex, HalfEdge and Face. These classes should be linked properly in the process of building up the mesh by calling Mesh class functions. Let's say they point to each other like this: class Vertex { HalfEdge *edge; }; class HalfEdge { Vertex* vert;
1
4467
by: ziroi | last post by:
Hello! I am new here to the forums and still learning C. I understand your policies on coursework, but I have an error that I've run around and around and can't figure out where my problem is with my assignment. I hope you guys can point me in the right direction. I have a program which has an array of linked lists, with specific struct data elements inside each node of these lists. The linked lists are created dynamically and data...
25
13062
by: J Caesar | last post by:
In C you can compare two pointers, p<q, as long as they come from the same array or the same malloc()ated block. Otherwise you can't. What I'd like to do is write a function int comparable(void *p, void *q) that will take any two pointers and decide whether they can be compared or not. I really can't think how to do this - any suggestions?
13
2892
by: smp | last post by:
Does anyone know why making a vector of pointers is so much less efficient than a vector of objects? For a simple example: int num = 20; vector<int*v_int_ptr; v_int_ptr.reserve(num); for(int i = 0; i < num; i++) { int* my_int_ptr = new int;
3
3046
by: Keith Thompson | last post by:
Victor <vhnguyenn@yahoo.comwrites: You're declaring an array of pointers to unsigned long long, but you're initializing the pointers with integer values. This is actually a constraint violation, and your compiler should have warned you about it. Your problem is either that you're invoking your compiler in some non-standard mode that inhibits the warnings, or getting warnings and not bothering to tell us about them.
0
9671
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9518
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10212
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10161
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10000
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6777
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3720
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.