-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_list.cpp
More file actions
176 lines (174 loc) · 5.2 KB
/
test_list.cpp
File metadata and controls
176 lines (174 loc) · 5.2 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#include <iostream>
#include <string>
#include "List.hpp"
int main()
{
using std::cout;
using std::endl;
using std::cin;
short option;
unsigned long position;
std::string word;
List<std::string> BiList;
cout << "Program testujący listę dwukierunkową.\n";
do
{
cout << "1 - wyczyść listę\n";
cout << "2 - sprawdź czy lista jest pusta\n";
cout << "3 - sprawdź ilość elementów\n";
cout << "4 - dodaj element na początek\n";
cout << "5 - dodaj element na koniec\n";
cout << "6 - dodaj element na pozycję n\n";
cout << "7 - zwróć element z początku\n";
cout << "8 - zwróć element z końca\n";
cout << "9 - zwróć element z pozycji n\n";
cout << "10 - usuń element z początku\n";
cout << "11 - usuń element z końca\n";
cout << "12 - usuń element na pozycji n\n";
cout << "13 - znajdź element\n";
cout << "14 - wydrukuj listę od początku\n";
cout << "15 - wydrukuj listę od końca\n";
cout << "16 - zakończ\n";
cin >> option;
switch (option)
{
case 1:
BiList.clear();
break;
case 2:
cout << (BiList.is_empty() ? "Jest pusta." : "Nie jest pusta.") << endl;
break;
case 3:
cout << BiList.size() << " elementów.\n";
break;
case 4:
cout << "Słowo: ";
cin >> word;
BiList.push_front(word);
break;
case 5:
cout << "Słowo: ";
cin >> word;
BiList.push_back(word);
break;
case 6:
cout << "Słowo: ";
cin >> word;
cout << "Pozycja: ";
cin >> position;
try
{
BiList.insert(word, position);
}
catch (List<std::string>::BadPosition)
{
cout << "Niewłaściwa pozycja.\n";
}
break;
case 7:
try
{
word = BiList.front();
}
catch (List<std::string>::NoElement)
{
cout << "Lista jest pusta.\n";
break;
}
cout << word << endl;
break;
case 8:
try
{
word = BiList.back();
}
catch (List<std::string>::NoElement)
{
cout << "Lista jest pusta.\n";
break;
}
cout << word << endl;
break;
case 9:
cout << "Pozycja: ";
cin >> position;
try
{
word = BiList.retrieve(position);
}
catch (List<std::string>::NoElement)
{
cout << "Lista jest pusta.\n";
break;
}
catch (List<std::string>::BadPosition)
{
cout << "Niewłaściwa pozycja.\n";
break;
}
cout << word << endl;
break;
case 10:
try
{
BiList.pop_front();
}
catch (List<std::string>::NoElement)
{
cout << "Lista jest pusta.\n";
}
break;
case 11:
try
{
BiList.pop_back();
}
catch (List<std::string>::NoElement)
{
cout << "Lista jest pusta.\n";
}
break;
case 12:
cout << "Pozycja: ";
cin >> position;
try
{
BiList.remove(position);
}
catch (List<std::string>::NoElement)
{
cout << "Lista jest pusta.\n";
}
catch (List<std::string>::BadPosition)
{
cout << "Niewłaściwa pozycja.\n";
}
break;
case 13:
cout << "Słowo: ";
cin >> word;
try
{
position = BiList.locate(word);
}
catch (List<std::string>::NoElement)
{
cout << "Nie znaleziono.\n";
break;
}
cout << "Na pozycji " << position << endl;
break;
case 14:
BiList.print_forwards();
break;
case 15:
BiList.print_backwards();
break;
case 16:
return 0;
default:
cout << "Niewłaściwa opcja.\n";
}
}
while (true);
}