-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1.cpp
More file actions
53 lines (47 loc) · 1.04 KB
/
1.cpp
File metadata and controls
53 lines (47 loc) · 1.04 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
#include <iostream>
#include <vector>
using namespace std;
//commit
template <typename T>
class Stack {
private:
vector<T> s;
public:
bool empty() {
if(s.empty()) return true;
else return false;
}
void push(const T& item) {
s.push_back(item);
}
T top() {
if(!s.empty()) return s.back();
else return 0;
}
void pop();
/*void pop() {
s.pop_back();
}*/
};
template <typename T>
void Stack<T>::pop() {
s.pop_back();
}
int main() {
Stack<int> stiva1;
Stack<float> stiva2;
int v1[5] = {1, 2, 3, 4, 5};
float v2[5] = {1.5, 2.5, 3.5, 4.5, 5.5};
for(int i = 0; i < 5; i++) {
stiva1.push(v1[i]);
stiva2.push(v2[i]);
}
cout<<"int: "<<stiva1.empty()<<endl;
cout<<"float: "<<stiva2.empty()<<endl;
cout<<"top int: "<<stiva1.top()<<endl;
cout<<"top float: "<<stiva2.top()<<endl;
stiva1.pop();
stiva2.pop();
cout<<"top int after push: "<<stiva1.top()<<endl;
cout<<"top float after push: "<<stiva2.top()<<endl;
}