This repository was archived by the owner on Jul 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbato_2.cpp
More file actions
73 lines (66 loc) · 1.44 KB
/
bato_2.cpp
File metadata and controls
73 lines (66 loc) · 1.44 KB
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
#include<iostream>
class Csample{
public:
Csample(){ //iniitialization
for(int i=0;i<1000;i++){
stack[i]=-1;
}
}
void push(int x); //enter
int get(int cat); //arrey's public
int eget(); //element's public
int pop(); //back
private:
int stack[1000];
int end_index=0;
};
/*enter*/
void Csample::push(int x){
stack[end_index]=x; //sub + element plus
end_index++;
}
/*arrey's public*/
int Csample::get(int cat){
return stack[cat];
}
/*element's public*/
int Csample::eget(){
return end_index;
}
/*back*/
int Csample::pop(){
int re=0; //return arrey;
re=stack[end_index - 1]; //plus-1 is display
stack[end_index -1]=-1;
end_index--;
return re;
}
int main(){
Csample cs1;
int a;
char q; //div
std::cin>>q; //div sub
while(q!='q'){
switch(q){
case 'i': //input
std::cin>>a; //num sub
cs1.push(a);
for(int i=0;i<cs1.eget();i++){
std::cout<<cs1.get(i)<<",";
}
std::cout<<std::endl;
break;
case 'o': //return outpot
std::cout<<"return:"<<cs1.pop()<<std::endl;
for(int i=0;i<cs1.eget();i++){
std::cout<<cs1.get(i)<<",";
}
std::cout<<std::endl;
break;
default: //i or o other
std::cout<<"error"<<std::endl;
}
std::cin>>q; //div sub
}
return 0;
}