Listing 2 Member function definitions for a queue of int using a non-nested cell type

//
// intq1.cpp - a queue of int (implementation)
//

#include "intq1.h"

void intq::append(const int &e)
   {
   intq_cell *p = new intq_cell(e, 0);
   if (first == 0)
      first = p;
   else
      last->next = p;
   last = p;
   }

void intq::clear()
   {
   intq_cell *p;
   while (first != 0)
      {
      p = first;
      first = first->next;
      delete p;
      }
   last = 0;
   }

void intq::print(ostream &os) const
   {
   intq_cell *p;
   for (p = first; p != 0; p = p->next)
      os << ' ' << p->element;
   }

int intq::remove(int &e)
   {
   if (first == 0)
      return 0;
   intq_cell *p = first;
   if ((first = first->next) == 0)
      last = 0;
   e = p->element;
   delete p;
   return 1;
   }

// End of File