-
Notifications
You must be signed in to change notification settings - Fork 0
/
stack.cpp
73 lines (57 loc) · 1.16 KB
/
stack.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Last sanity check: 2020-05-18
//
// main.cpp
// Cpp
//
// Created by Alex Seceleanu on 4/9/18.
// Copyright © 2018 Alex Seceleanu. All rights reserved.
#include<stdio.h>
#include<iostream>
#include<set>
#include<stack>
#include<queue>
using namespace std;
class Person
{
private:
string name;
public:
Person(): name("name") {}
Person( string name):
name(name) { cout << "\t\t\tPerson is created: "<<name<<endl;}
~Person()
{
cout << "\t\t\t Object destroyed!"<<endl;
}
bool operator< (const Person &other) const
{
return name < other.name;
}
void print() const
{
cout << name << endl;
}
};
int main()
{
//LIFO functionality
stack<Person> test;
test.push(Person("Alex"));
test.push(Person("Vlad"));
test.push(Person("Andrei"));
// Person t1 = test.top();
// t1.print();
//
// test.pop();
// Person t2 = test.top();
// t2.print();
cout<<endl<<endl;
cout<< "Printing stack:"<<endl;
while(test.size() > 0)
{
Person &t = test.top();
t.print();
test.pop();
}
return 0;
}