1.栈
https://blog.youkuaiyun.com/优快云___优快云/article/details/82918436
1 #include <stdio.h>
2 #include <stdlib.h>
3
4 typedef struct link_node
5 {
6 int info;
7 struct link_node *next;
8 }N;
9
10 /*创建一个空的链式栈*/
11 N *init()
12 {
13 return NULL;
14 }
15
16 /*对链式栈进行初始化*/
17 N *creat(N *top)
18 {
19 int x;
20 N *p;
21 printf("以输入-1为结束\n");
22 scanf("%d",&x);
23 while(x!=-1)
24 {
25 p=(N*)malloc(sizeof(N));
26 p->info=x;
27 p->next=top;
28 top=p;
29 scanf("%d",&x);
30 }
31 return top;
32 }
33
34 /*取得链式栈的栈顶结点值*/
35 int read(N *top)
36 {
37 if(!top)
38 {
39 printf("\n该链式栈是空的\n");
40 }
41 return top->info;
42 }
43
44 /*输出链式栈中各结点的值*/
45 void display(N *top)
46 {
47 N *p=top;
48 if(!top)
49 {
50 printf("该链式栈是空的\n");
51 }
52 else
53 {
54 while(p)
55 {
56 printf("%d ",p->info);
57 p=p->next;
58 }
59 printf("\n");
60 }
61 }
62
63 /*链式栈的插入操作*/
64 N *insert(N *top,int x)
65 {
66 N *q=top,*p;
67 p=(N*)malloc(sizeof(N));
68 p->info=x;
69 p->next=top;
70 top=p;
71 return top;
72 }
73
74 /*链式栈的删除操作*/
75 N *dele(N *top)
76 {
77 N *p=top;
78 if(!top)
79 {
80 printf("\n该链式栈是空的,无法进行删除\n");return NULL;
81 }
82 top=top->next;
83 free(p);
84 return top;
85 }
86
87 int main()
88 {
89 N* top = init();
90 top = creat(top);
91 display(top);
92 int i = read(top);
93 printf("%d\n",i);
94 top = insert(top,5);
95 display(top);
96 top = dele(top);
97 display(top);
98
99 return 0;
100 }
2.栈c++实现
https://blog.youkuaiyun.com/zichen_ziqi/article/details/80807989
1 #include <iostream>
2 using namespace std;
3
4 template <class T>
5 class stack{
6 private:
7 struct Node{
8 T data;
9 struct Node *next;
10 };
11 Node *head;
12 int len;
13 public:
14 stack()
15 {
16 head = NULL;
17 len = 0;
18 }
19 //创建一个栈
20 void create()
21 {
22 int x;
23 Node *p;
24 cout << "以输入-1为结束" << endl;
25 cin >> x ;
26 while(x!=-1)
27 {
28 p=new Node;
29 p->data=x;
30 p->next=head;
31 head=p;
32 cin >> x ;
33 len++;
34 }
35 }
36 //入栈
37 void push(T x)
38 {
39 Node *q = new Node;
40 q->data = x;
41 q->next = head;
42 len++;
43 }
44 //出栈
45 T top()
46 {
47 Node *p;
48 T data;
49 data = head->data;
50 p = head;
51 head = head->next;
52 delete(p);
53 len--;
54 return data;
55 }
56 //返回栈内元素的个数
57 int size()
58 {
59 return len;
60 }
61 };
62
63 int main()
64 {
65 stack<int> s;
66 s.create();
67 s.push(7);
68 cout << s.size() << endl;
69 cout << s.top() << endl;
70 cout << s.size() << endl;
71
72 return 0;
73 }
3.用两个栈实现队列的功能
https://blog.youkuaiyun.com/weixin_40671425/article/details/83006485
1 #include<stdio.h>
2 #include<stdlib.h>
3
4 #define STACK_INIT_SIZE 10
5
6 typedef struct stack{
7 int *base;
8 int *top;
9 int stacksize;
10 }stack;
11
12 int initStack(stack *s)//构造一个空栈
13 {
14 s->base = (int *)malloc(sizeof(stack)*STACK_INIT_SIZE);
15 if(s->base == NULL)
16 exit(-1);
17 s->top = s->base;
18 s->stacksize = STACK_INIT_SIZE;
19 return 1;
20 }
21
22 void push(stack *s,int num)//压栈
23 {
24 *s->top++ = num;//注意 优先级
25 }
26
27 int pop(stack *s)//弹栈
28 {
29 if(s->base == s->top)//空栈,无栈可弹
30 return -1;
31 return *(--s->top);
32 }
33
34 int main()
35 {
36 stack s1,s2;
37 initStack(&s1);
38 initStack(&s2);
39 int nums[] = {1,2,3,4,5,6};
## 最后
**自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。**
**深知大多数Java工程师,想要提升技能,往往是自己摸索成长,自己不成体系的自学效果低效漫长且无助。**
**因此收集整理了一份《2024年嵌入式&物联网开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。**







**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上嵌入式&物联网开发知识点,真正体系化!**
[**如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!**](https://bbs.youkuaiyun.com/topics/618654289)
**由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新**!!
geZXqBQc-1715716539343)]
**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上嵌入式&物联网开发知识点,真正体系化!**
[**如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!**](https://bbs.youkuaiyun.com/topics/618654289)
**由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新**!!