SOURCE FILE: cListP.h
// *********************************************************
// Header file cListP.h for the ADT list.
// Circular, singly-linked, pointer-based implementation.
// *********************************************************
#include <iostream>
#include <iomanip>
#include <string>
using namespace std ;
typedef string listItemType ;
struct listNode; // linked list node
typedef listNode* ptrType; // pointer to node
class listClass
{
public:
// constructors and destructor:
/* -------------------------------------------------- */
listClass();
// default constructor
// initializes the list -- makes it an empty list
/* -------------------------------------------------- */
~listClass();
// destructor
// makes the list empty and
// recycles all the memory used
// by elements of the list.
// list operations:
/* -------------------------------------------------- */
bool ListIsEmpty() const;
// Determines whether a list is empty.
// Precondition: None.
// Postcondition: Returns true if the list is empty,
// otherwise returns false.
/* -------------------------------------------------- */
int ListLength() const;
// Determines the length of a list.
// Precondition: None.
// Postcondition: Returns the number of items
// that are currently in the list.
/* -------------------------------------------------- */
void ListInsert(int NewPosition, listItemType NewItem,
bool& Success);
// Inserts an item into a list.
// Precondition: NewPosition indicates where the
// insertion should occur. NewItem is the item to be
// inserted.
// Postcondition: If insertion was successful, NewItem is
// at position NewPosition in the list, other items are
// renumbered accordingly, and Success is true;
// otherwise Success is false.
// Note: Insertion will not be successful if
// NewPosition < 1 or > ListLength()+1.
/* -------------------------------------------------- */
void ListDelete(int Position, bool& Success);
// Deletes an item from a list.
// Precondition: Position indicates where the deletion
// should occur.
// Postcondition: If 1 <= Position <= ListLength(),
// the item at position Position in the list is
// deleted, other items are renumbered accordingly,
// and Success is true; otherwise Success is false.
/* -------------------------------------------------- */
void ListRetrieve(int Position, listItemType& DataItem,
bool& Success) const;
// Retrieves a list item by position number.
// Precondition: Position is the number of the item to
// be retrieved.
// Postcondition: If 1 <= Position <= ListLength(),
// DataItem is the value of the desired item and
// Success is true; otherwise Success is false.
/* -------------------------------------------------- */
private:
int Size; // number of items in list
/* -------------------------------------------------- */
ptrType Last ;
// pointer to linked list of items
// (It points to last item in a circular,
// singly linked structure)
/* -------------------------------------------------- */
ptrType PtrTo(int Position) const;
// Returns a pointer to the Position-th node
// in the linked list.
/* -------------------------------------------------- */
}; // end class
// End of header file.