diff --git a/src/algorithms/mergesort.c b/src/algorithms/mergesort.c index af3a659..c7f95eb 100644 --- a/src/algorithms/mergesort.c +++ b/src/algorithms/mergesort.c @@ -3,8 +3,8 @@ #include -static void merge(Application* app, size_t left, size_t middle, size_t right); -static void mergesort_rec(Application* app, size_t left, size_t right); +static int merge(Application* app, size_t left, size_t middle, size_t right); +static int mergesort_rec(Application* app, size_t left, size_t right); static int* tmp = NULL; @@ -15,19 +15,24 @@ void mergesort(Application* app) free(tmp); } -static void mergesort_rec(Application* app, size_t left, size_t right) +static int mergesort_rec(Application* app, size_t left, size_t right) { if(right > left) { size_t middle = (left + right) / 2; - mergesort_rec(app, left, middle); - mergesort_rec(app, middle + 1, right); + if(mergesort_rec(app, left, middle)) + return 1; - merge(app, left, middle, right); + if(mergesort_rec(app, middle + 1, right)) + return 1; + + return merge(app, left, middle, right); } + + return 0; } -static void merge(Application* app, size_t left, size_t middle, size_t right) +static int merge(Application* app, size_t left, size_t middle, size_t right) { for(size_t k = left; k <= middle; k++) { @@ -59,9 +64,9 @@ static void merge(Application* app, size_t left, size_t middle, size_t right) k++; if(update_screen(app)) - return; + return 1; } visualizer_data.array[right] = tmp[i]; - update_screen(app); + return update_screen(app); } \ No newline at end of file diff --git a/src/application.c b/src/application.c index f23e06b..e05de69 100644 --- a/src/application.c +++ b/src/application.c @@ -46,7 +46,7 @@ int init_application(Application* app, int width, int height, const char* title) app->active_visualizer = &histogram_visualizer; - visualizer_data.array_size = 2500; + visualizer_data.array_size = 1500; visualizer_data.array = (int*)malloc(visualizer_data.array_size * sizeof(int)); // TODO: Check if NULL