Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commitb6e654657da058e9a438ec4583fac8028758dfb4 (patch)
Author
 Syndamia <kamen@syndamia.com>
2022-12-29 09:09:41 +0200
Committer
 Syndamia <kamen@syndamia.com>
2022-12-29 09:09:41 +0200
Filesc23fd470e2c94e7acd2123676eed3fb5e4645769
uni-projects-b6e654657da058e9a438ec4583fac8028758dfb4.tar
uni-projects-b6e654657da058e9a438ec4583fac8028758dfb4.tar.gz
uni-projects-b6e654657da058e9a438ec4583fac8028758dfb4.zip
Parentb6a3bfe4691089112d25870fbb9bcc83c67f9d26 (diff)
[SDP/P/exa] Removed hard coded example and added user input reading
diff --git a/Year 2/Structures and data algorithms/Project/exa/SkipList.hpp b/Year 2/Structures and data algorithms/Project/exa/SkipList.hpp
index 125013b..4821aef 100644
--- a/Year 2/Structures and data algorithms/Project/exa/SkipList.hpp
+++ b/Year 2/Structures and data algorithms/Project/exa/SkipList.hpp
@@ -32,6 +32,7 @@ public:
bool addSkip(const T&, const T&);
T pop();
T& front();
+ T& back();
unsigned size();
bool empty();
@@ -176,6 +177,14 @@ T& SkipList<T>::front() {
}
template <class T>
+T& SkipList<T>::back() {
+ if (empty())
+ throw "Back called on empty SkipList!";
+
+ return tail->value;
+}
+
+template <class T>
unsigned SkipList<T>::size() {
return listSize;
}
diff --git a/Year 2/Structures and data algorithms/Project/exa/main.cpp b/Year 2/Structures and data algorithms/Project/exa/main.cpp
index 88bf9ce..0beae8b 100644
--- a/Year 2/Structures and data algorithms/Project/exa/main.cpp
+++ b/Year 2/Structures and data algorithms/Project/exa/main.cpp
@@ -3,30 +3,41 @@
#include <iostream>
int main() {
- SkipList<std::string> cities;
- cities.push("Sofia");
- cities.push("Pazardzhik");
- cities.push("Plovdiv");
- cities.push("Dimitrovgrad");
- cities.push("StaraZagora");
- cities.push("NovaZagora");
- cities.push("Yambol");
- cities.push("Karnobat");
- cities.push("Burgas");
+ std::cout << "Брой на градовете през които преминава пътническия влак: ";
+ unsigned n = 0;
+ std::cin >> n;
- cities.addSkip("Sofia", "Plovdiv");
- cities.addSkip("Plovdiv", "NovaZagora");
- cities.addSkip("Dimitrovgrad", "NovaZagora");
- cities.addSkip("StaraZagora", "Yambol");
- cities.addSkip("NovaZagora", "Burgas");
+ std::cout << "Имената на градовете: ";
+ SkipList<std::string> cities;
+ std::string temp1;
+ while (n-- > 0) {
+ std::cin >> temp1;
+ cities.push(temp1);
+ }
- cities.print(std::cout) << std::endl;
+ std::cout << "Брой на директните връзки: ";
+ std::cin >> n;
+ std::cout << "Директни връзки:" << std::endl;
+ std::string temp2;
+ while (n-- > 0) {
+ std::cin >> temp1 >> temp2;
+ cities.addSkip(temp1, temp2);
+ }
- std::deque<std::string> locs = { "Plovdiv", "StaraZagora", "Yambol", "Burgas" };
- std::deque<std::string> path = cities.shortestSublistIncluding(locs);
+ std::cout << "Брой на градовете на Аня и Ванката: ";
+ std::cin >> n;
+ std::cout << "Градовете на Аня и Ванката: ";
+ std::deque<std::string> visitCities;
+ while (n-- > 0) {
+ std::cin >> temp1;
+ visitCities.push_back(temp1);
+ }
+ visitCities.push_back(cities.back());
- for (auto loc : path) {
- std::cout << loc << ", ";
+ std::cout << "Решение:" << std::endl;
+ std::deque<std::string> visited = cities.shortestSublistIncluding(visitCities);
+ for (auto city : visited) {
+ std::cout << city << ", ";
}
std::cout << std::endl;
}