Summary Files Commits Branches @commit @diff @stats
path: root / Year 2 / Structures and data algorithms / 06-Seminar-09.10.2022 / exercises.cpp
diff options
context:
space:
mode:
Commit593e009ac517b305dd6af7656c635f900715ce13 (patch)
Author
 Syndamia <kamen@syndamia.com>
2022-12-25 12:40:28 +0200
Committer
 Syndamia <kamen@syndamia.com>
2022-12-25 12:40:28 +0200
Files42df92bfae3646a9052097715b3da58eb292b0f7 /Year 2/Structures and data algorithms/06-Seminar-09.10.2022/exercises.cpp
uni-projects-593e009ac517b305dd6af7656c635f900715ce13.tar
uni-projects-593e009ac517b305dd6af7656c635f900715ce13.tar.gz
uni-projects-593e009ac517b305dd6af7656c635f900715ce13.zip
Parente5ce6898294e7610fd6a0404ef513fddee60663d (diff)
[SDP/P05-06] Fixed folder dates
1 files changed, 0 insertions, 131 deletions
-rw-r--r--Year 2/Structures and data algorithms/06-Seminar-09.10.2022/exercises.cpp131
diff --git a/Year 2/Structures and data algorithms/06-Seminar-09.10.2022/exercises.cpp b/Year 2/Structures and data algorithms/06-Seminar-09.10.2022/exercises.cpp
deleted file mode 100644
index 1981501..0000000
--- a/Year 2/Structures and data algorithms/06-Seminar-09.10.2022/exercises.cpp
+++ /dev/null
@@ -1,131 +0,0 @@
-#include <list>
-#include <iostream>
-#include <queue>
-#include "DoublyLinkedList.hpp"
-
-// Ex1
-
-template<class T>
-void insertSorted(std::list<T>& ll, const T& elem) {
- auto iter = ll.cbegin();
- while (*iter < elem)
- ++iter;
- ll.insert(iter, elem);
-}
-
-void ex1() {
- std::list<int> l;
- l.push_back(1);
- l.push_back(2);
- l.push_back(4);
- l.push_back(5);
-
- for (int n : l) std::cout << n << " ";
- std::cout << std::endl;
- insertSorted(l, 3);
- for (int n : l) std::cout << n << " ";
- std::cout << std::endl;
-}
-
-// Ex2
-
-void print(DoublyLinkedList<std::queue<int>*>& dll) {
- for (std::queue<int>* val : dll)
- std::cout << val->front() << " ";
- std::cout << std::endl;
-}
-
-int operate(int a, int b, char op) {
- switch(op) {
- case '+': return a + b;
- case '-': return a - b;
- case '*': return a * b;
- case '/': return a / b;
- default: return 0;
- }
-}
-
-int evaluateRPQueue(std::queue<int>& eq) {
- int accum = eq.front() - '0';
- eq.pop();
- char buf;
- while (!eq.empty()) {
- buf = eq.front();
- eq.pop();
- accum = operate(accum, buf - '0', eq.front());
- eq.pop();
- }
- return accum;
-}
-
-void evaluateQueues(DoublyLinkedList<std::queue<int>*>& dll) {
- for (std::queue<int>* eq : dll) {
- eq->push(evaluateRPQueue(*eq));
- }
-}
-
-template <class T>
-bool isSymmetricBad(DoublyLinkedList<std::queue<T>*> dll) {
- while (!dll.empty()) {
- if (dll.back()->front() != dll.front()->front())
- return false;
- dll.popBack();
- if (dll.empty()) return true;
- dll.popFront();
- }
- return true;
-}
-
-template <class T>
-bool isSymmetric(DoublyLinkedList<std::queue<T>*>& dll) {
- auto frontIter = dll.begin();
- auto backIter = --dll.end();
-
- while (frontIter != backIter) {
- if ((*frontIter)->front() != (*backIter)->front())
- return false;
- ++frontIter;
- if (frontIter == backIter) return true;
- --backIter;
- }
- return true;
-}
-
-void ex2() {
- DoublyLinkedList<std::queue<int>*> dll;
- dll.pushBack(new std::queue<int>());
- dll.back()->push('4');
- dll.back()->push('5');
- dll.back()->push('+');
- dll.pushBack(new std::queue<int>());
- dll.back()->push('1');
- dll.back()->push('6');
- dll.back()->push('+');
- dll.back()->push('7');
- dll.back()->push('*');
- dll.pushBack(new std::queue<int>());
- dll.back()->push('8');
- dll.pushBack(new std::queue<int>());
- dll.back()->push('1');
- dll.back()->push('7');
- dll.back()->push('*');
- dll.back()->push('7');
- dll.back()->push('*');
- dll.pushBack(new std::queue<int>());
- dll.back()->push('2');
- dll.back()->push('3');
- dll.back()->push('*');
- dll.back()->push('3');
- dll.back()->push('+');
-
- print(dll);
-
- evaluateQueues(dll);
- print(dll);
-
- std::cout << isSymmetric(dll) << std::endl;
-}
-
-int main() {
- ex2();
-}