Skip to content

Commit

Permalink
add solutions to 5 and 6 from sorting problems
Browse files Browse the repository at this point in the history
  • Loading branch information
witek-formanski committed Nov 24, 2023
1 parent 133ad82 commit f302184
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/cw7/zad5/beakers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
T(n,k) = O(k)
M(n,k) = O(k)
algorytm HUffmana
*/

#include <algorithm>
#include <vector>
// #include <deque>
#include <queue>

float get_min_and_increment(std::vector<float>::const_iterator it, std::queue<float> q) {
float min;
if (*it == std::min(*it, q.front())) {
min = *it;
*it++;
} else {
min = q.front();
q.pop();
}
return min;
}

float beakers(const std::vector<float> v, int k) {
float min_sum;
auto it = v.begin();
std::queue<float> q;

for (int i = 0; i < k; i++) {
min_sum = get_min_and_increment(it, q);
min_sum += get_min_and_increment(it, q);
q.push(min_sum);
}

return std::min(*it, q.front());
}
Empty file added src/cw7/zad6/cruise.cpp
Empty file.

0 comments on commit f302184

Please sign in to comment.