#include
#include
Typedef struct stacknode {
CHAR DATA;
Struct stacknode * next;
Linkstack;
Linkstack * TOP;
Void InitStack (Linkstack * TOP)
{
TOP = (Linkstack *) Malloc (Sizeof (Linkstack);
TOP-> DATA = NULL;
}
INT EmptyStack (Linkstack * TOP)
{
IF (top! = null)
Return 0;
Else
Return 1;
}
Void Push (Linkstack * Top, Char X)
{
Linkstack * P;
P = (Linkstack *) Malloc (Sizeof (Linkstack);
P-> DATA = X;
P-> Next = NULL;
TOP-> Next = P;
TOP = P;
}
Void Pop (Linkstack * Top, Char & X)
{
Linkstack * P;
EmptyStack (TOP))
Printf ("Underflow / N");
Else
{
P = TOP;
X = TOP-> DATA;
TOP = TOP-> Next;
Free (p);
}
}
Void gettop (Linkstack * Top, Char & X)
{
EmptyStack (TOP))
Printf ("Underflow, Stack IS Empty / N);
Else
X = TOP-> DATA;
}
Void Display (Linkstack * TOP)
{
Linkstack * P;
P = TOP;
CHAR CH;
While (p! = null)
{
Printf ("% C", P-> Data);
P = P-> next;
}
Printf ("% C", P-> Data);
}
void main ()
{
CHAR C1, C2, C3;
Linkstack * P;
Printf ("Setup An Empty Stack./N");
INITSTACK (P);
Printf ("Push a char 通o the stack.enter the char: / n");
While ((c1 = getchar ())! = '/ n')
PUSH (P, C1);
Printf ("" The Stack now is: ");
Display (p);
Printf ("/ n");
Gettop (p, c2);
Printf ("Top of the Stack IS:% C / N", C2);
Printf ("Now Pop The Top Elem if The Stack Is Not Empty./N");
POP (p, c3);
Printf ("" The Stack now is: ");
Display (p);
Printf ("/ n");
}