本文主要介绍了C++实现推箱子功能附加回撤示例,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
跟着B站老师 做的,链接[C/]
编码环境:VS2019
利用 链栈实现的回撤功能。
LinkStack.h
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
#pragma once
#ifdef _cplusplus
extern "C"
{
#endif
#include <fstream>
#include <iostream>
#include<stdbool.h>
using namespace std;
#define OK 1
#define ERROR 0
#define OVERFLOW -2
struct Point
{
int r;
int c;
int data;
};
typedef struct _State
{
Point pos[3];
}Data,State;
typedef struct StackNode
{
Data data;
struct StackNode* next;
} StackNode, * LinkStack;
void InitStack(LinkStack& S)
{
S = NULL;
}
void Push(LinkStack& S, Data e)
{
LinkStack p;
p = new StackNode;
p->data = e;
p->next = S;
S = p;
printf ( "ok\n" );
}
void Pop(LinkStack& S)
{
LinkStack p;
if (S == NULL)
return ;
p = S;
S = S->next;
delete p;
}
Data GetTop(LinkStack S)
{
if (S != NULL)
return S->data;
}
bool empty(LinkStack& S) {
if (S == NULL)
return true ;
else return false ;
}
1 本网站名称:米米素材网
2 本站永久网址:https://www.mimisucai.cn
3 本网站的文章部分内容可能来源于网络,仅供大家学习与参考,如有侵权进行删除处理。
4 本站一切资源不代表本站立场,并不代表本站赞同其观点和对其真实性负责。
5 本站一律禁止以任何方式发布或转载任何违法的相关信息,访客发现请向站长举报
6 本站资源大多存储在云盘,如发现链接失效,请联系我们我们会第一时间更新。
|
发表评论