-
Notifications
You must be signed in to change notification settings - Fork 0
/
SqDoubleStack.cpp
57 lines (50 loc) · 1.11 KB
/
SqDoubleStack.cpp
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
//
// Created by Shanwer on 2023/10/31.
//
#include "SqDoubleStack.h"
void initDoubleStack(SqStack &st) //st为引用型参数
{
st.top=-1;
}
void DestroyDoubleStack(SqStack st)
{ }
int pushDoubleStack(SqStack &st, ElemType x)
{ if (st.top==MaxSize-1) { //栈满
return 0;
} else {
st.top++;
st.data[st.top]=x;
return 1;
}
}
int popDoubleStack(SqStack &st, ElemType &x) //x为引用型参数
{
if (st.top == -1) { //栈空
return 0;
} else {
x = st.data[st.top];
st.top--;
return 1;
}
}
int getDoubleStackTop(SqStack st, ElemType &x) //x为引用型参数
{
if (st.top == -1) { //栈空
return 0;
} else {
x = st.data[st.top];
return 1;
}
}
void printAllDoubleStack(SqStack st){
for(int i = st.top; i!=-1;i--){
printf("%c\n",st.data[i]);
}//破坏了栈的定义,调试用
}
bool doubleStackIsEmpty(SqStack st)
{
if (st.top != -1)
return false;
else
return true;
}