-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_stack.cpp
74 lines (72 loc) · 1.92 KB
/
test_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
73
74
#include <iostream>
#include <string>
#include "Stack.hpp"
int main()
{
using std::cout;
using std::endl;
using std::cin;
short option;
std::string word;
Stack<std::string> stack;
cout << "Program testujący stos.\n";
do
{
cout << "1 - wyczyść stos\n";
cout << "2 - sprawdź czy stos jest pusty\n";
cout << "3 - sprawdź ilość elementów\n";
cout << "4 - dodaj element\n";
cout << "5 - zwróć element ze szczytu\n";
cout << "6 - usuń element\n";
cout << "7 - wydrukuj stos\n";
cout << "8 - zakończ\n";
cin >> option;
switch (option)
{
case 1:
stack.clear();
break;
case 2:
cout << (stack.is_empty() ? "Jest pusty." : "Nie jest pusty.") << endl;
break;
case 3:
cout << stack.size() << " elementów.\n";
break;
case 4:
cout << "Słowo: ";
cin >> word;
stack.push(word);
break;
case 5:
try
{
word = stack.top();
}
catch (Stack<std::string>::NoElement)
{
cout << "Stos jest pusty.\n";
break;
}
cout << word << endl;
break;
case 6:
try
{
stack.pop();
}
catch (Stack<std::string>::NoElement)
{
cout << "Stos jest pusty.\n";
}
break;
case 7:
stack.print();
break;
case 8:
return 0;
default:
cout << "Niewłaściwa opcja.\n";
}
}
while (true);
}