Stack data structure stack.h

xiaoxiao2021-03-06  96

///

///

// Stack data structure stack.h //

///

//

#include

Template Class Stack;

Template

Class StackNode

{

Friend Class Stack ;

Private:

TYPE DATA;

StackNode * link;

StackNode (Type D = 0, StackNode * l = null): LINK (L), DATA (D) {}

}

Template

Class Stack

{

PUBLIC:

Stack (): TOP (NULL), NumItem (0) {}

Void Push (Type Item);

TYPE POP ();

TYPE GETTOP ();

Void makeempty ();

Bool isempty ();

Int getnum ();

Private:

Int NumItem;

StackNode * top;

}

Template

Void Stack :: Push (Type Item)

{

TOP = New StackNode (item, top);

Numitem ;

}

Template

TYPE Stack :: pop ()

{

StackNode * p;

TYPE TEMP;

Temp = TOP-> DATA;

P = TOP;

TOP = TOP-> LINK;

Delete P;

Numitem -

Return Temp;

}

Template

TYPE Stack :: gettop ()

{

Return Top-> Data;

}

Template

Bool Stack :: iSempty ()

{

Return Top == NULL;

}

Template

Void Stack :: makeempty ()

{

DELETE TOP;

}

Template

Int stack :: getnum ()

{

Return NumItem;

}

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

New Post(0)