Website Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
4 files changed, 43 insertions, 1 deletions
-rw-r--r--Seminar02/task03.cpp2
-rw-r--r--Seminar07/README.md2
-rw-r--r--Seminar07/counting-sort.cpp40
-rw-r--r--Seminar07/Сортиращи алгоритми.pdfbin0 -> 335838 bytes
diff --git a/Seminar02/task03.cpp b/Seminar02/task03.cpp
index d460551..1c7a095 100644
--- a/Seminar02/task03.cpp
+++ b/Seminar02/task03.cpp
@@ -12,7 +12,7 @@ bool isDigit(char c) {
}
int eval(int fst, int snd, char op) {
- assert(isOperation(c));
+ assert(isOperation(op));
switch (op) {
case '+':
diff --git a/Seminar07/README.md b/Seminar07/README.md
new file mode 100644
index 0000000..eef8bee
--- /dev/null
+++ b/Seminar07/README.md
@@ -0,0 +1,2 @@
+## Сортиращи алгоритми
+Прикачвам ви мои стари записки за сортиращи алгоритми. \ No newline at end of file
diff --git a/Seminar07/counting-sort.cpp b/Seminar07/counting-sort.cpp
new file mode 100644
index 0000000..a00f742
--- /dev/null
+++ b/Seminar07/counting-sort.cpp
@@ -0,0 +1,40 @@
+#include<iostream>
+#include<vector>
+#include<algorithm>
+#include<cassert>
+
+const int ELEMENTS_RANGE = 1000;
+
+void countingSort(std::vector<int>& v) {
+ std::vector<int> count(ELEMENTS_RANGE, 0);
+ std::vector<int> result(v.size());
+
+ for (size_t i = 0; i < v.size(); i++)
+ count[v[i]]++;
+
+ for (size_t i = 1; i < ELEMENTS_RANGE; i++)
+ count[i] += count[i - 1];
+
+ for (int i = v.size() - 1; i >= 0; i--) {
+ result[count[v[i]] - 1] = v[i];
+ count[v[i]]--;
+ }
+
+ v = std::move(result);
+}
+
+int main() {
+ std::vector<int> v;
+ const int length = 100000;
+
+ for (size_t i = 0; i < length; i++)
+ v.push_back(rand() % ELEMENTS_RANGE);
+
+ countingSort(v);
+
+ assert(std::is_sorted(v.begin(), v.end()));
+
+ // for (int x : v) {
+ // std::cout << x << " ";
+ // }
+} \ No newline at end of file
diff --git a/Seminar07/Сортиращи алгоритми.pdf b/Seminar07/Сортиращи алгоритми.pdf
new file mode 100644
index 0000000..4cee79a
--- /dev/null
+++ b/Seminar07/Сортиращи алгоритми.pdf
Binary files differ