Created
April 25, 2021 15:55
-
-
Save Khuzha/4eda64a2d71b5c0c6c6dc5af232a5728 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void quicksort(t_sprite *arr, int first, int last) | |
{ | |
t_sprite tmp; | |
t_qs data; | |
if (first < last) | |
{ | |
data.middle = arr[(first + last) / 2].dist; | |
data.i = first - 1; | |
data.j = last + 1; | |
while (1) | |
{ | |
data.i++; | |
while (arr[data.i].dist > data.middle && data.i < last) | |
data.i++; | |
data.j--; | |
while (arr[data.j].dist < data.middle && data.j > 0) | |
data.j--; | |
if (data.i >= data.j) | |
break ; | |
tmp = arr[data.i]; | |
arr[data.i] = arr[data.j]; | |
arr[data.j] = tmp; | |
} | |
quicksort(arr, first, data.i - 1); | |
quicksort(arr, data.j + 1, last); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i = 0, sprite: y = 21.500000, x = 65.500000, dist = 4319.815536
i = 1, sprite: y = 4.500000, x = 58.500000, dist = 3134.741981
i = 2, sprite: y = 20.500000, x = 41.500000, dist = 1837.113094
i = 3, sprite: y = 14.500000, x = 41.500000, dist = 1658.641549
i = 4, sprite: y = 16.500000, x = 27.500000, dist = 815.323706
i = 5, sprite: y = 26.500000, x = 3.500000, dist = 570.819095
i = 6, sprite: y = 2.500000, x = 5.500000, dist = 8.762683
i = 7, sprite: y = 1.500000, x = 12.500000, dist = 100.421604