-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy path3-3-2.cpp
58 lines (57 loc) · 892 Bytes
/
3-3-2.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
58
#include<iostream>
using namespace std;
#define MAXSIZE 10
#define ELEMTYPE char
typedef struct{
ELEMTYPE data[MAXSIZE];
int top; //top 指针
}SqStack;
void InitStack(SqStack &stk){
stk.top=0;
}
bool StackEmpty(SqStack stk){
if(!stk.top)return true;
return false;
}
//注意:一定要加引用型!
bool push(SqStack &stk,ELEMTYPE x){
//MAXIZE
if(stk.top<MAXSIZE){
stk.data[stk.top++]=x;
return true;
}
return false;
}
bool pop(SqStack &stk,ELEMTYPE &x){
if(stk.top>0){
x=stk.data[--stk.top];
return true;
}
return false;
}
bool gettop(SqStack stk,ELEMTYPE &x){
if(stk.top){
x=stk.data[stk.top-1];
return true;
}
return false;
}
int main(){
SqStack s;
InitStack(s);
char x;
cin>>x;
while(x!='q'){
switch(x){
case 'H':
push(s,x);
break;
case 'S':
cout<<x<<" ";
}
cin>>x;
}
while(pop(s,x))cout<<x<<" ";
cout<<endl;
return 0;
}