Listing 7 Tracks the number of list objects in existence at any given time in the execution of the program

//
// list.cpp - list implementation using a nested class
// with global variables counting the objects
//

#include <stdio.h>

#include "list.h"

unsigned list_count = 0;

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

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

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