hi
i have 2 structure and i don't understund the linked lists very well yet so please can anyone tell me the difference between this 2 structure:
thankyouCode:struct node{ int a; struct node *next; }; struct list { struct node *head; };
hi
i have 2 structure and i don't understund the linked lists very well yet so please can anyone tell me the difference between this 2 structure:
thankyouCode:struct node{ int a; struct node *next; }; struct list { struct node *head; };
The first one is a structure containing one int and a pointer to another structure of the same kind.
The second one is quite useless because you only have a pointer to one (probably the first node of a linked list or the head of a BST) node inside it.
You can use the following code instead, because it makes more sense:
Code:struct node { int a; struct node *next; }; struct node *head;
Last edited by mog; 06-22-2007 at 08:51 AM.
It wouldn't be useless if he put, say, a "tail" pointer in there as well. Don't knock something just because it looks redundant -- it could be that way because of an intention to expand it later, or it might have contained other stuff in the past which has since been removed, etc...
Here's a better idea: You tell us what you think the difference is, and we'll tell you if you are right.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"