forked from AuthorityWu/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.c
More file actions
33 lines (26 loc) · 471 Bytes
/
stack.c
File metadata and controls
33 lines (26 loc) · 471 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "stack.h"
int main()
{
Stack *myStack;
int i,x;
//初始化栈
StackInitial(&myStack);
//将1-10的元素推入栈
for(i=1;i<=10;i++){
StackPush(myStack,i);
}
//获取栈顶元素
StackTop(myStack,&x);
printf("当前栈顶数据元素为:%d\n",x);
//将栈内的元素推出栈
printf("依次出栈的数据元素序列如下:\n");
while(StackNotEmpty(myStack)){
StackPop(myStack,&x);
printf("%d ",x);
}
//销毁链表,释放内存
Destroy(myStack);
getchar();
getchar();
return 0;
}