Mercurial > public > algo-animator
comparison src/main.c @ 38:8ed1256dd518
finish quick sort and add insertion sort
author | Dennis C. M. <dennis@denniscm.com> |
---|---|
date | Fri, 30 Jun 2023 19:25:38 +0100 |
parents | b1a605eb721a |
children | b656ed2e8957 |
comparison
equal
deleted
inserted
replaced
37:0e2121235413 | 38:8ed1256dd518 |
---|---|
5 int window_height = 1080; | 5 int window_height = 1080; |
6 int vpadding = 150; | 6 int vpadding = 150; |
7 int rect_width = 5; | 7 int rect_width = 5; |
8 int space = 1; | 8 int space = 1; |
9 | 9 |
10 struct Algo algos[2]; | 10 struct Algo algos[4]; |
11 int selected_algo = 0; | 11 int selected_algo = 0; |
12 int algos_size; | 12 int algos_size; |
13 | 13 |
14 struct AlgoArgs algo_args; | 14 struct AlgoArgs algo_args; |
15 struct ThreadState thread_state; | 15 struct ThreadState thread_state; |
74 glClear(GL_COLOR_BUFFER_BIT); | 74 glClear(GL_COLOR_BUFFER_BIT); |
75 | 75 |
76 glBegin(GL_QUADS); | 76 glBegin(GL_QUADS); |
77 | 77 |
78 int x = 0; | 78 int x = 0; |
79 for (int i = 0; i < algo_args.arr_size - 1; i++) { | 79 for (int i = 0; i < algo_args.arr_size; i++) { |
80 | 80 |
81 if (algo_args.arr[i].current) { | 81 if (algo_args.arr[i].current) { |
82 glColor3f(1.0, 1.0, 1.0); | 82 glColor3f(1.0, 1.0, 1.0); |
83 } else { | 83 } else { |
84 glColor3f(1.0, 0.7569, 0.0); | 84 glColor3f(1.0, 0.7569, 0.0); |
302 algos[0].function = bubble_sort; | 302 algos[0].function = bubble_sort; |
303 | 303 |
304 strcpy(algos[1].name, "Selection sort"); | 304 strcpy(algos[1].name, "Selection sort"); |
305 algos[1].function = selection_sort; | 305 algos[1].function = selection_sort; |
306 | 306 |
307 strcpy(algos[2].name, "Quick sort"); | |
308 algos[2].function = quick_sort; | |
309 | |
310 strcpy(algos[3].name, "Insertion sort"); | |
311 algos[3].function = insertion_sort; | |
312 | |
307 algos_size = sizeof(algos) / sizeof(algos[0]); | 313 algos_size = sizeof(algos) / sizeof(algos[0]); |
308 | 314 |
309 create_array(algo_args.arr, algo_args.arr_size, window_height, vpadding); | 315 create_array(algo_args.arr, algo_args.arr_size, window_height, vpadding); |
310 randomize_array(algo_args.arr, algo_args.arr_size); | 316 randomize_array(algo_args.arr, algo_args.arr_size); |
311 | 317 |