Queue data structure queue.h

xiaoxiao2021-03-06  92

///

///

// Queue data structure queue.h //

///

//

#include

Template Class Queue;

Template Class QueuNode

{

Friend class queue ;

Private:

TYPE DATA;

QueuNode * link;

QueuNode (Type D = 0, QueuNode * L = NULL): DATA (D), LINK (L) {}

}

Template Class Queue

{

PUBLIC:

Queue (): REAR (NULL), Front (NULL) {}

~ Queue ();

Void Enqueue (Type Item);

TYPE DELQUE ();

TYPE GETFRONT ();

Void makeempty ();

Bool isempty () {return front == NULL;}

Private:

QueuNode * Front, * REAR;

}

Template

Queue :: ~ queue ()

{

QueuNode * p;

While (Front! = NULL)

{

p = front;

Front = front-> link;

Delete P;

}

}

Template

Void queue :: enqueue (Type item)

{

IF (Front == Null)

Front = Rear = new queuenode (item, null);

Else

REAR = Rear-> link = new queuenode (item, null);

}

Template

TYPE Queue :: delqueue ()

{

QueuNode * p = front;

TYPE TEMP = P-> DATA ;;

Front = front-> link;

Delete P;

Return Temp;

}

Template

TYPE Queue :: getfront ()

{

Return Front-> Data;

}

Template

Void queue :: makeempty ()

{

QueuNode * p;

While (Front! = NULL)

{

p = front;

Front = front-> link;

Delete P;

}

}

转载请注明原文地址:https://www.9cbs.com/read-102113.html

New Post(0)