Commit 7350926d authored by Nawasan Wisitsingkhon's avatar Nawasan Wisitsingkhon

init

parents
Pipeline #1949 failed with stages
/main
\ No newline at end of file
#include <iostream>
#include <vector>
#include "sorting.h"
#define E6 1000000;
#define E7 10000000;
#define E8 100000000;
#define U8 256;
int ARR_LEN = E6;
int main() {
ARR_LEN = ARR_LEN * 2;
vector<int> arr(ARR_LEN, 0);
for (int i = 0; i < ARR_LEN; i++) {
// arr[i] = rand() % 4294967295;
arr[i] = rand() % 256;
}
quick_sort(arr);
return 0;
}
\ No newline at end of file
#include <vector>
using namespace std;
void quick_sort_node(vector<int> &arr, int st, int ed, vector<int> &worker) {
int k = st - 1;
int tmp;
for (int i = st; i < ed; i++) {
if (arr[i] <= arr[ed - 1]) {
k += 1;
tmp = arr[i];
arr[i] = arr[k];
arr[k] = tmp;
}
}
int len2 = ed - k - 1;
if (k > 1) {
worker.push_back(st);
worker.push_back(k);
}
if (len2 > 1) {
worker.push_back(k + 1);
worker.push_back(ed);
}
}
void quick_sort_linear(vector<int> &arr, vector<int> &worker) {
while (worker.size()) {
int w2 = worker[worker.size() - 1];
worker.pop_back();
int w1 = worker[worker.size() - 1];
worker.pop_back();
if (w1 == w2) continue;
quick_sort_node(arr, w1, w2, worker);
}
}
void quick_sort(vector<int> &arr) {
vector<int> worker;
worker.push_back(0);
worker.push_back(arr.size());
quick_sort_linear(arr, worker);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment