Can somebody help explain linked lists to me?
I read the tutorial on this site, and I read SAMS Teach yourself in 21 Days...but I still don't really understand linked lists![]()
I understand the idea that its data and pointers, and the pointer keeps it moving down to the next set of data (the link in the list)
But I don't really see how this could be useful or why everybody says it is so important.
Code from Tutorial
Parts I don't understand are underlined.
Any help would be appreciatedCode:struct node { int x; node *next; }; int main() { node *root; // This won't change, or we would lose the list in memory node *conductor; // This will point to each node as it traverses the list root = new node; // Sets it to actually point to something root->next = 0; // Otherwise it would not work well root->x = 12; // why are we jumping to 12? How would this be done in a real-world prog? conductor = root; // The conductor points to the first node if ( conductor != 0 ) { while ( conductor->next != 0) conductor = conductor->next; } conductor->next = new node; // Creates a node at the end of the list conductor = conductor->next; // Points to that node conductor->next = 0; // Prevents it from going any further conductor->x = 42; }![]()
Where are these puppies used? Why are they important? What are the alternatives? Why are they better than the alternatives?



LinkBack URL
About LinkBacks





it is good when it is free 