Linked List
Go to solution
Solved by WanderingFool,
How you make a linked list print out can change significantly from language to language (Concept is similar but the look is quite different)
Assuming C++
struct Node { int value; struct Node *Next;}//Assumes Next will be 0 when list has endedvoid printList(struct Node* parent) { struct Node* current = parent; while(current != 0) { std::cout << current->value; current = current->Next; //Set current to whatever is next in the list }}
C#
void printList(LinkedList list) { foreach(var item in list) { Console.print(item); //Sorry can't remember the console print off hand but whatever the print function is }}
As for double linked lists, it all depends on the language again...basically for c++ you do the same as a linked list but add an extra variable that points to the previous node (code should be similar for adding)
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now