Last active
August 29, 2015 13:57
-
-
Save goatandsheep/9358782 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 sort_vectors(const short *v[], int type); | |
-1-terminated vector of shorts: -1 denotes out of bounds? | |
so the vector is of length n+1, when you have n elements, | |
where the n+1th element is -1 | |
no negative elements | |
short: 16-bits | |
long: 32-bits | |
sort the values by: | |
-smallest to largest (vice versa) | |
pointers are being switched so you don't have to copy the data; | |
only copy the pointer to the data | |
pointers 5 4 1 3 7 5 8 | |
values: 1 3 5 7 9 0 3 | |
pointers : 1 3 4 5 | |
switch the values a and b: | |
temp = a | |
a = b | |
b = temp | |
temp = *a | |
*a = *b | |
*b = temp | |
sum: sum of all elements in vector (except for terminator) | |
if type == 0{ | |
goto sort_the_vectors_by_sum elements/vector | |
} | |
for each vector sum all elements (except for terminator) | |
sort the vectors by their sum | |
sort_the_vectors_by_sum: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment