Click on circlist.h to get source.
// File Circlist/circlist.h
// the following switch makes sure circlist is declared only once
#ifndef __circlist
#define __circlist
#include "cell.h"
#include <iostream>
using namespace std;
class circlist {// a circular list object
public:
int empty(void) {return rear == rear->next; }
protected:
circlist(void)
// the initial object is a single cell with info 0
{cout << "Made a circlist" << endl; rear = new cell(0); }
virtual ~circlist(void);
// somehow the g++ requires destructor to be virtual (otherwise warning)
void push(int x){// add a cell with info x at the beginning of list
rear->next = new cell(x, rear->next); };
int pop(void);// remove front cell, return its info (see below)
void enter(int x){
// put x into info at last cell, add a cell with 0 at rear
rear->info = x; rear->next = new cell(0, rear->next);
rear = rear->next; };
private:
cell *rear; // pointer to last cell in list
friend int main(void); // for purpose of testing circlist in main
friend ostream& operator<<(ostream&, circlist&); // overloaded <<
};
ostream& operator<<(ostream&, circlist&);
#endif