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

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