home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / CTECHAPP.ZIP / CONTAINR.ZIP / DBLLIST.CPP < prev    next >
C/C++ Source or Header  |  1990-01-27  |  2KB  |  102 lines

  1. //  Header:     DblList  (Doubly-Linked Lists)
  2. //  Version:    3.20
  3. //
  4. //  Language:   C++ 2.0
  5. //  Environ:    Any
  6. //
  7. //  Purpose:    Provides a general doubly-linked list class
  8. //
  9. //  Written by: Scott Robert Ladd
  10.  
  11. #include "DblList.hpp"
  12.  
  13. extern "C"
  14.     {
  15.     #include "stddef.h"
  16.     }
  17.  
  18. // duplication method
  19. void DoublyLinkedList::Copy(const DoublyLinkedList & dl)
  20.     {
  21.     Head = NULL;
  22.     Tail = NULL;
  23.  
  24.     DListNode * temp = dl.Head;
  25.  
  26.     while (temp != NULL)
  27.         {
  28.         if (Tail == NULL)
  29.             {
  30.             Tail = new DListNode;
  31.  
  32.             if (Tail == NULL)
  33.                 ErrorHandler();
  34.  
  35.             Head = Tail;
  36.  
  37.             Tail->Next    = NULL;
  38.             Tail->Prev    = NULL;
  39.             Tail->DataPtr = temp->DataPtr;
  40.             }
  41.         else
  42.             {
  43.             Tail->Next = new DListNode;
  44.  
  45.             if (Tail->Next == NULL)
  46.                 ErrorHandler();
  47.  
  48.             Tail->Next->Next    = NULL;
  49.             Tail->Next->Prev    = Tail;
  50.             Tail->Next->DataPtr = temp->DataPtr;
  51.  
  52.             Tail = Tail->Next;
  53.             }
  54.  
  55.         temp = temp->Next;
  56.         }
  57.     }
  58.  
  59. // constructor
  60. DoublyLinkedList::DoublyLinkedList() : Container()
  61.     {
  62.     Head  = NULL;
  63.     Tail  = NULL;
  64.     }
  65.  
  66. // copy contructor
  67. DoublyLinkedList::DoublyLinkedList(const DoublyLinkedList & dl)
  68.     {
  69.     Copy(dl);
  70.     }
  71.  
  72. // assignment operator
  73. void DoublyLinkedList::operator = (const DoublyLinkedList & dl)
  74.     {
  75.     this->Empty();
  76.  
  77.     Count = dl.Count;
  78.  
  79.     Copy(dl);
  80.     }
  81.  
  82. // destructor
  83. DoublyLinkedList::~DoublyLinkedList()
  84.     {
  85.     this->Empty();
  86.     }
  87.  
  88. // remove all items from a list
  89. void DoublyLinkedList::Empty()
  90.     {
  91.     DListNode * temp, * hold;
  92.  
  93.     temp = Head;
  94.  
  95.     while (temp != NULL)
  96.         {
  97.         hold = temp->Next;
  98.         delete temp;
  99.         temp = hold;
  100.         }
  101.     }
  102.