顺序栈的基本操作(今天晚自习写的)

 1 #include<stdio.h>
 2 #define MAXSIZE 10
 3 typedef int ELemType;
 4 typedef struct ZZ {
 5     ELemType data[MAXSIZE];
 6     int top;
 7 }Sqstack;
 8 //初始化顺序栈
 9 int initStact(Sqstack *L){
10     L->top = -1;
11     return printf("初始化成功
");
12 }
13 //销毁栈
14 void DestroyStact(Sqstack* L) {
15 
16 }
17 //进栈
18 int Push(Sqstack* L) {
19     int n;    
20     printf("请输入你想进栈的数字");    
21     printf("(输入-1以停止输入)
");
22     for (int i=0;;i++) {
23         if (L->top == MAXSIZE-1) {
24             return printf("栈以满停止输入
");
25         }
26         printf("请输入第%d个数", i + 1);
27         scanf("%d", &n);
28         if (n == -1) {
29             return printf("  以停止输入
");
30         }
31             L->top++;
32         L->data[L->top] = n;
33     }
34 }
35 //出栈
36 int Pop(Sqstack *L){
37     int n;
38     for(;L->top!=-1;){
39         if(L->top==-1){
40             return printf("已经出栈完毕
");
41         }
42             
43         n=L->data[L->top];
44              L->top--;
45         printf("栈中数据有");
46         printf("%d  ",n);
47     }
48 }
49 int main() {
50     Sqstack L;
51     initStact(&L);
52     Push(&L);
53     Pop(&L);
54 }
原文地址:https://www.cnblogs.com/longlonglonglong/p/10951942.html