forked from taniadovzhenko/CppPracticum
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask10.2.cpp
More file actions
119 lines (92 loc) · 1.65 KB
/
task10.2.cpp
File metadata and controls
119 lines (92 loc) · 1.65 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
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
#include <iostream>
#include <stack>
namespace Our{
template <class T=int>
struct Node{ // (ptr, data)
T data;
Node* ptr;
};
template <typename T=int>
class Stack{
// (1,NULL) , (2, ptr ->1), (3, ptr->2 )
size_t l;
Node<T>* current;
public:
Stack() {l=0; current = nullptr;}
T push(T x);
void pop();
size_t len();
T top();
bool isempty();
void show(){
while(!isempty()){
std::cout<<top()<<", ";
pop();
}
std::cout<<"\n\n";
}
};
template <class T>
T Stack<T>::push(T x){
Node<T>* z = new Node<T>();
z->data = x;
z->ptr = current;
current = z;
l++;
}
template <class T>
void Stack<T>::pop(){
if(l==0) return;
Node<T>* prev = current->ptr;
delete current;
current = prev;
l--;
}
template <class T>
size_t Stack<T>::len(){
return l;
}
template <class T>
T Stack<T>::top(){
return current->data;
}
template <class T>
bool Stack<T>::isempty(){
return (l==0);
}
};
/* Input of array */
int input(int* arr) {
int x;
int k= 0;
do{
// x = ...
std::cin>>x;
arr[k++] = x;
} while(x!=0);
return k;
}
int main(){
//int a[10];
//int k= input(a); // k<10
Our::Stack<> q;
int x;
int k= 0;
do{
// x = ...
std::cin>>x;
q.push(x);
} while(x!=0);
q.show();
std::stack<unsigned> w;
k=0;
do{
// x = ...
std::cin>>x;
w.push(x);
} while(x!=0);
while (!w.empty()){
std::cout<<w.top()<<", ";
w.pop();
}
}