Summary Files Commits Branches @commit @diff @stats
path: root / Year 2 / Structures and data algorithms / 05-Seminar-02.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/05-Seminar-02.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, 124 deletions
-rw-r--r--Year 2/Structures and data algorithms/05-Seminar-02.10.2022/exercises.cpp124
diff --git a/Year 2/Structures and data algorithms/05-Seminar-02.10.2022/exercises.cpp b/Year 2/Structures and data algorithms/05-Seminar-02.10.2022/exercises.cpp
deleted file mode 100644
index 0317cc3..0000000
--- a/Year 2/Structures and data algorithms/05-Seminar-02.10.2022/exercises.cpp
+++ /dev/null
@@ -1,124 +0,0 @@
-#include "LinkedList.hpp"
-#include <iostream>
-#include <stack>
-#include <queue>
-
-// Ex1
-
-template <class T>
-void shuffle(LinkedList<T>& l) {
- auto fast = l.begin(), slow = l.begin(), end = l.end();
- while (fast != end) {
- ++fast;
- if (fast != end) {
- ++fast;
- ++slow;
- }
- }
- int pops = 0;
- while (++slow != end) {
- l.pushFront(*slow);
- pops++;
- }
- while (pops-- > 0)
- l.popBack();
-}
-
-template <class T>
-void print(LinkedList<T>& l) {
- for (const T& elem : l) {
- std::cout << elem << " ";
- }
- std::cout << std::endl;
-}
-
-void ex1() {
- LinkedList<int> l;
- l.pushBack(1);
- l.pushBack(2);
- l.pushBack(3);
- l.pushBack(4);
- l.pushBack(5);
-
- print(l);
- shuffle(l);
- print(l);
-}
-
-// Ex2
-
-void print(LinkedList<std::stack<int>*>& l) {
- for (const std::stack<int>* elem : l) {
- if (!elem->empty())
- std::cout << elem->top() << " ";
- }
- std::cout << std::endl;
-}
-
-#define min(a,b) (a<b) ? a : b
-
-void equalize(LinkedList<std::stack<int>*>& l) {
- std::queue<size_t> valueSize;
- std::queue<int> valueHolder;
- for (std::stack<int>* elem : l) {
- valueSize.push(elem->size());
- while (!elem->empty()) {
- valueHolder.push(elem->top());
- elem->pop();
- }
- }
- std::queue<int> leftovers;
- size_t amountPer = valueHolder.size() / l.size();
- for (std::stack<int>* elem : l) {
- size_t cpyOriginals = min(amountPer, valueSize.front());
- for (size_t i = 0; i < cpyOriginals; i++) {
- elem->push(valueHolder.front());
- valueHolder.pop();
- }
- for (int i = valueSize.front() - amountPer; i > 0; i--) {
- leftovers.push(valueHolder.front());
- valueHolder.pop();
- }
- valueSize.pop();
- }
- for (std::stack<int>* elem : l) {
- for (size_t i = amountPer - elem->size(); i > 0; i--) {
- elem->push(leftovers.front());
- leftovers.pop();
- }
- }
-}
-
-void ex2() {
- LinkedList<std::stack<int>*> l;
- l.pushBack(new std::stack<int>());
- l.back()->push(1);
- l.back()->push(2);
- l.back()->push(3);
- l.back()->push(4);
- l.back()->push(5);
- l.pushBack(new std::stack<int>());
- l.back()->push(6);
- l.back()->push(7);
- l.pushBack(new std::stack<int>());
- l.back()->push(8);
- l.back()->push(9);
- l.back()->push(10);
- l.back()->push(11);
- l.pushBack(new std::stack<int>());
- l.back()->push(12);
-
- print(l);
- equalize(l);
- print(l);
-}
-
-// Ex 3
-
-// LinkedListNode<int>* partition(LinkedListNode<int>* head, int x) {
-//
-// }
-
-int main() {
- ex2();
-}