home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_11_07 / 1107123a < prev    next >
Text File  |  1993-05-06  |  602b  |  41 lines

  1. //
  2. // list.cpp - list implementation using a nested class
  3. // with global variables counting the objects
  4. //
  5.  
  6. #include <stdio.h>
  7.  
  8. #include "list.h"
  9.  
  10. unsigned list_count = 0;
  11.  
  12. list::list(unsigned n)
  13.     {
  14.     first = last = new node (n, 0);
  15.     ++list_count;
  16.     }
  17.  
  18. list::~list()
  19.     {
  20.     node *p;
  21.     while ((p = first) != 0)
  22.         {
  23.         first = first->next;
  24.         delete p;
  25.         }
  26.     --list_count;
  27.     }
  28.  
  29. void list::add(unsigned n)
  30.     {
  31.     if (last->number != n)
  32.         last = last->next = new node (n, 0);
  33.     }
  34.  
  35. void list::print()
  36.     {
  37.     for (node *p = first; p != 0; p = p->next)
  38.         printf("%4u ", p->number);
  39.     }
  40.  
  41.