Website Summary Files Commits Branches @commit @diff @stats
path: root / Additional / equalize.cpp
diff options
context:
space:
mode:
Commit9eed63a37a808c59990feaaaa3e1725dfdd31f3c (patch)
Author
 Stoycho Kyosev <stoycho.kk@gmail.com>
2023-10-30 22:33:14 +0200
Committer
 Stoycho Kyosev <stoycho.kk@gmail.com>
2023-10-30 22:33:14 +0200
Filesbc22e2b8407f9207c7a5a8ef999f41446c0cee19 /Additional/equalize.cpp
Data-structures-and-algorithms-9eed63a37a808c59990feaaaa3e1725dfdd31f3c.tar
Data-structures-and-algorithms-9eed63a37a808c59990feaaaa3e1725dfdd31f3c.tar.gz
Data-structures-and-algorithms-9eed63a37a808c59990feaaaa3e1725dfdd31f3c.zip
Parent0f17a224d2934c748b32b908f74724b3299d263a (diff)
Add SI consultation
1 files changed, 0 insertions, 60 deletions
-rw-r--r--Additional/equalize.cpp60
diff --git a/Additional/equalize.cpp b/Additional/equalize.cpp
deleted file mode 100644
index 263ccd2..0000000
--- a/Additional/equalize.cpp
+++ /dev/null
@@ -1,60 +0,0 @@
-#include<iostream>
-#include"../Seminar04/linked-list-utils.h"
-#include<stack>
-
-using ListNode = LinkedListNode<std::stack<int>>;
-
-// O(k*n) памет, където n е дължината на списъка а k размера на най - големия стек
-// O(k*n) време
-void equalize(ListNode* ll) {
- std::stack<int> temp;
- ListNode* iter = ll;
-
- while(iter) {
- while(!iter->data.empty()) {
- temp.push(iter->data.top());
- iter->data.pop();
- }
- iter = iter->next;
- }
-
- iter = ll;
-
- while(!temp.empty()) {
- if(iter == nullptr) {
- iter = ll;
- }
- iter->data.push(temp.top());
- temp.pop();
- iter = iter->next;
- }
-}
-
-void printStack(std::stack<int> s) {
- int size = s.size();
-
- std::cout << "[";
-
- while (!s.empty()) {
- std::cout << s.top() << " ";
- s.pop();
- }
-
- std::cout << "] -> " << size << std::endl;
-}
-
-int main() {
- ListNode* ll = fromList(
- {
- std::stack<int>({1, 4}),
- std::stack<int>({6, 7, 8, 9, 5}),
- std::stack<int>({10, 11, 12}),
- std::stack<int>({1, 41}),
- std::stack<int>({6, 7, 8, 9, 5, 7, 9, 0, 10, 20, 30})
- }
- );
-
- equalize(ll);
- printLinkedList(ll, printStack);
- freeList(ll);
-} \ No newline at end of file