【小白成长撸】--链栈(C语言版)

 1 // 链栈.cpp : 定义控制台应用程序的入口点。
 2 //
 3 
 4 #include "stdafx.h"
 5 #include <stdio.h>
 6 #include <stdlib.h>//malloc的头文件
 7 
 8 typedef struct line_stack//栈包装
 9 {
10     int x;
11     struct line_stack *next;
12 }link;
13 
14 void pushes(link **top, int x);
15 void pops(link **top);
16 
17 int main()
18 {
19     return 0;//这页代码只提供目标子函数,没有写主函数
20 }
21 
22 void pushes(link **top, int x)//入栈,
23 {
24     link *p;
25 
26     p = (link *)malloc(sizeof(link));
27 
28     p->x = x;
29     p->next = (*top);
30 
31     (*top) = p;
32 
33     return;
34 }
35 
36 void pops(link **top)//出栈
37 {
38     link *p;
39 
40     if ((*top) == NULL)
41     {
42         printf_s("空栈
");
43         return;
44     }
45 
46     p = (*top);
47     (*top) = p->next;
48     free(p);
49     
50     return;
51 }
原文地址:https://www.cnblogs.com/zpc-uestc/p/5820130.html