#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#define MAX 100
typedef struct{
int Data[max];
int top;
}stack;
Stack s;
Initialization succeeded 1
int Initstack (Stack s) {
S.top=-1;
return 1;
}
Non-empty 1
int Stackempty (Stack s) {
if ( -1==s.top)
return 0;
return 1;
}
Under 1
int Stackfull (Stack s) {
if (max-1==s.top)
return 0;
return 1;
}
For length success 1 output length
int Stacklength (Stack s) {
printf ("Length%d", s.top+1);
return 1;
}
Access stack top returns 1 output elements
int GetTop (Stack s,int *e) {
E=s.data;
printf ("Stack top element is%d", *e);
return 1;
}
Into the Stack success 1
int Push (Stack s,int e) {
++s.top;
S.data[s.top]=e;
printf ("Into the stack success!") \ n ");
return 0;
}
Out of Stack success 1
int Pop (Stack s,int *e) {
*e=s.data[s.top];
s.top--;
return 1;
}
int main () {
int i,e,*e1,*e2;
Stack L;
printf ("Now start the operation of the station!\n");
if (1!=initstack (L)) {
printf ("Initialization failed, press any key to exit!\n");
Getch ();
Exit (0);
}
if (1!=stackempty (L)) {
printf ("The space on the stack is empty!") \ n ");
Exit (0);
}
printf ("Do you want to do a stack operation?") 1-yes ");
scanf ("%d", &i);
if (1==i) {
Loop
printf ("Enter the element you want to stack into:");
scanf ("%d", &e);
if (1!=stackfull (L)) {
printf ("Stack space is full!") \ n ");
printf ("Do you want to do a stack operation 1 or access top operation 2?") \ n ");
printf ("Please enter your choice:");
scanf ("%d", &i);
if (i==1)
Goto Pop;
else if (i==2)
Goto GetTop;
else{
printf ("The operation failed, press any key to exit!") \ n ");
Getch ();
Exit (0);
}
}
else{
Push (l,e);
printf ("Do you want to continue into the stack?" 1-yes ");
scanf ("%d", &i);
if (i==1)
Goto Loop;
}
}
else{
printf ("Do you want to do a stack operation 1 or access top operation 2?") \ n ");
printf ("Please enter your choice:");
scanf ("%d", &i);
if (i==1)
Goto Pop;
else if (i==2)
Goto GetTop;
else{
printf ("The operation failed, press any key to exit!") \ n ");
Getch ();
Exit (0);
}
}
Pop
Pop (L,E1);
printf ("Do you want to continue with the stack operation?") 1 is ");
scanf ("%d", &i);
if (1==i)
Goto Pop;
GetTop
GetTop (L,E2);
printf ("The operation of the sequential stack has ended!");
return 0;
}
Data structure note 1 sequence stack