Listing 4 An implementation of the list class

//
// list.cpp - list implementation
//

#include <stdio.h>

#include "list.h"

list::list(unsigned n)
       {
       first = last = new node (n, 0);
       }

list::~list()
       {
       node *p;
       while ((p = first) != 0)
              {
              first = first->next;
              delete p;
              }
       }

void list::add(unsigned n)
       {
       if (last->number != n)
              last = last->next = new node (n, 0);
       }

void list::print()
       {
       for (node *p = first; p != 0; p = p->next)
              printf("%4u ", p->number);
       }
// End of File