871,759 Members | Top Members by Rank
JOIN DANIWEB MEMBER LOG IN
Software Development > C++ > Generic Doubly-Linked List (C++)
Ad: Hostly Web Hosting for Your Business
C++ Code Snippet Views: 36397
C++ Code Snippet (Toggle Plain Text)
#include <iostream>1.
2.
template <typename T>3.
class double_linked4.
{5.
struct node6.
{7.
T data;8.
node* prev;9.
node* next;10.
node(T t, node* p, node* n) : data(t), prev(p), next(n) {}11.
};12.
node* head;13.
node* tail;14.
public:15.
double_linked() : head( NULL ), tail ( NULL ) {}16.
template<int N>17.
double_linked( T (&arr) [N]) : head( NULL ), tail ( NULL )18.
{19.
for( int i(0); i != N; ++i)20.
push_back(arr[i]);21.
}22.
23.
bool empty() const { return ( !head || !tail ); }24.
operator bool() const { return !empty(); } 25.
void push_back(T);26.
void push_front(T);27.
T pop_back();28.
T pop_front();29.
30.
~double_linked()31.
{32.
while(head)33.
0
Generic Doubly-Linked List (C++)
by Bench on Jul 18th, 2007
This code snippet outlines a simple, no-frills linked list. Tested under MSVC++ 2003
and Comeau, but not guaranteed bug free. Snippet includes example main() .
This snippet is intended as an example of a possible implementation of a linked list
class (Of which there are many variations) For a better linked list, use the STL <list>
library.
C++ Database
High Scalability, High Availability Large Data Sets, High
Performance
www.versant.com/objectdatabase
Examples Of Proposals
Download a Strong Business Proposal Just Fill-in the
Blanks & Print!
Biztree.com
TVideoGrabber Video SDK
for Developers. Quick add Video Features to your
Application
www.datastead.com
C++
C++ Experts are Ready to Help. Join Now for Free.
CFanatic.com/CPlusPlus-Programming
Editorial Hardware & Software Software Development Web Development Internet Marketing Business Exchange Community Center
Generic Doubly-Linked List (C++) - C++ http://www.daniweb.com/code/snippet216960.html
1 of 5 23/12/2553 18:5
4