![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
![]() |

|
| Programming tutorials All Knowledge Info and links to posted here |
![]() |
|
C/C++ Doubly Linked List
|
LinkBack | Thread Tools | Display Modes |
|
|
#1 (permalink) |
|
Administrator
Posts: 876
Join Date: Oct 2005
Rep Power: 10
IM:
|
Code:
struct Node{
public:
Member* info; //type is arbitrary, to the linked list implementation
Node* next; //used to point to next node
Node* prev; //used to point to previous node
Node():prev(NULL),next(NULL) {} //default constructor
Node(Node* n):prev(n),next(NULL) {} //prev known constructor
Node(Node* n, Node* m):prev(n),next(m) {} //prev and next known constructor
~Node() { delete info; delete next; } //destructor
};
this list would be held by a pointer: Code:
Node* head; head = &(new Node(&head);//create Node which knows prev(head) and next is NULL then each node is attatched with a similar fasion. To search such a list use a while loop: Code:
Node* n = head;
while(n->next){
//loop code
n = n->next;
}
|
|
|
|
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Power To-Do List 1.1 | ErrorFix | Application Downloads | 0 | 27-Feb-2008 01:40 AM |
| Task List 1.1 | ErrorFix | Application Downloads | 0 | 27-Feb-2008 12:25 AM |
| Export a Distribution list thats inside the contact list | Iphone | Microsoft Windows xp error | 1 | 03-Apr-2007 01:22 AM |
| 2D C. Geometry: Redirecting edges (Linked half-edge list) | Iphone | Programming Error ! | 1 | 29-Mar-2007 03:13 AM |
| the list | driverdownloads | Fun N Light Error! | 0 | 27-Mar-2007 04:01 AM |