(Latest Revision: Sun Apr 15 02:38:56 PDT 2001 )
// *********************************************************
// Implementation file deque.cpp for the ADT deque.
// Pointer-based implementation.
// *********************************************************
#include <iostream.h>
#include <iomanip.h>
#include "deque.h" // header file
#include <stddef.h> // for NULL
// The deque is implemented as a circular doubly linked list
// with one external pointer to the back of the deque.
struct dequeNode
{
dequeItemType Item;
ptrType Next;
ptrType Prev;
}; // end struct
dequeClass::dequeClass() : BackPtr(NULL), Size(0)
{
} // end default constructor
dequeClass::~dequeClass()
{
/* FILL THIS IN */
} // end destructor
bool dequeClass::IsEmpty() const
{
/* FILL THIS IN */
} // end IsEmpty
int dequeClass::Length() const
{
/* FILL THIS IN */
} // end Length
void dequeClass::AddInRear(dequeItemType NewItem, bool& Success)
{
// create a new node
ptrType NewPtr = new dequeNode;
Success = bool(NewPtr != NULL); // check allocation
if (Success)
{ // allocation successful; set data portion of new node
NewPtr->Item = NewItem;
// insert the new node
if (IsEmpty())
{ // insertion into empty deque
NewPtr->Next = NewPtr;
NewPtr->Prev = NewPtr;
}
else
{ // insertion into nonempty deque
NewPtr->Next = BackPtr->Next;
NewPtr->Prev = BackPtr ;
BackPtr->Next->Prev = NewPtr ;
BackPtr->Next = NewPtr;
/* Note: This works if we are adding the second element */
} // end if
BackPtr = NewPtr; // new node is at back
Size++ ;
} // end if
} // end AddInRear
void dequeClass::AddInFront(dequeItemType NewItem, bool& Success)
{
/* FILL THIS IN */
} // end AddInFront
void dequeClass::TakeOutFront(dequeItemType& DequeFront, bool& Success)
{
/* FILL THIS IN */
} // end TakeOutFront
void dequeClass::TakeOutRear(dequeItemType& DequeRear, bool& Success)
{
/* FILL THIS IN */
} // end TakeOutRear
void dequeClass::Print() const
{
/* FILL THIS IN */
}
// End of implementation file.