/* */stack subsystem
# include & lt; Stdio. H>
# include & lt; The malloc. H>
# define MAXSIZE a maximum length of 100 * 100/* array/
Typedef int DataType./* defined DataType of type int */
Typedef struct stacknode stack storage type *//* chain
{
DataType data;/* define node data fields */
Struct stacknode * next;/* define node pointer field */
} LinkStack;
LinkStack * InitStack ()
{/* * initialization stack chain function/
LinkStack * S;
S=NULL;
Return S;/* initialize the stack is empty */
}
Int EmptyStack (LinkStack * S)
{/* judgment stack empty function */
If (S==NULL)/* the stack is empty */
return 1;
The else
return 0;
}
LinkStack * Push LinkStack * S, DataType (x)
{/* * into the stack function/
LinkStack * p;
P=(LinkStack *) malloc (sizeof (LinkStack)); Generate new node *//*
p-> data=https://bbs.csdn.net/topics/x;/* x into the new node data fields */
p-> Next=S;/* first insert the new node chain table before */
S=p;/* */new node as a stack
Return S;/* S */return stack
}
Void MenuStack ()
{/* display function */food list
Printf (" \ n stack subsystem ");
Printf (" \ n==================================================");
Printf (" \ n | | 1 -- initialization stack ");
Printf (" \ n | 2 | - stack operation ");
Printf (" \ n | 3 -- reverse operation | ");
Printf (" \ n return to | | 0 - ");
Printf (" \ n==================================================");
Printf (" \ n please input menu (0-3) : ");
}
The main ()
{
Int I, n, flag;
LinkStack * S;
DataType x;
Char ch1 and ch2, a;
Ch1='y'
While (ch1=='y' | | ch1=='y')
{MenuStack ();
The scanf (" % c ", & amp; Ch2);
getchar();
The switch (ch2)
{
Case '1' :
S=InitStack ();
Printf (" stack initialization is complete!" );
break;
Case '2' :
Printf (" please input to the number of elements in the stack, ");
The scanf (" % d ", & amp; N);
Printf (" please enter the % d stack integers: ", n);
for(i=0; i
The scanf (" % d ", & amp; X);
S=Push (S, x);
}
Printf (" into the stack success!" );
break;
Case '0' :
Ch1='n'. break;
Default:
Printf (" input is wrong, please input 3-0 to choose!" );
}
If (ch2!='0')
{printf (" \ n press the enter key to continue, press any key to return to the main menu! \n");
A=getchar ();
If (a!='\ xA')
{
getchar(); Ch1='n'.
}
}
}
}
CodePudding user response:
for helpCodePudding user response: