Friday, July 31, 2009

Double linked list complete code in c++?

The class code to implement isn't that difficult to write unless you desire to be very generic with the objects handled. If you require use with generic objects, definitely consider STL first!





class Node {


public String data; // The data being stored in the node


public Node%26amp; next; // A reference to the next node; null for last node


public Node%26amp; prev; // A reference to the previous node; null for first node


}





class List {


public Node%26amp; firstNode; // points to first node of list; null for empty list


public Node%26amp; lastNode; // points to last node of list; null for empty list


}





usage --


node = list.firstNode;


while node != null


%26lt;do something with node.data%26gt;


node = node.next;





I'm certain you'd want to use helper methods instead of public attributes but this was simpler to type...

Double linked list complete code in c++?
Why do you want to re-invent the wheel?


It is already a part of STL.





See this link for more details : http://www.sgi.com/tech/stl/List.html
Reply:Wow, you're just so specific on the details of the question. Let me get right on that...


No comments:

Post a Comment