-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselection.c
63 lines (51 loc) · 1.03 KB
/
selection.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#define SIZE (16)
void print_arr(uint32_t *arr) {
int i = SIZE;
printf("Colors array (%d-bit):\n", SIZE);
while(i-- > 0) {
printf(">> 0x%08x, %d\n", *arr, *arr);
arr++;
}
}
int main(int argc, char *argv[]) {
uint32_t hex_color_codes[SIZE] = {
0x00000000,
0x00FFFFFF,
0x00FF0000,
0x0000FF00,
0x000000FF,
0x00FFFF00,
0x0000FFFF,
0x00FF00FF,
0x00C0C0C0,
0x00808080,
0x00800000,
0x00808000,
0x00008000,
0x00800080,
0x00008080,
0x00000080
};
int i, j, min;
uint32_t temp;
(void) argc;
(void) argv;
print_arr(hex_color_codes);
// all about searchin idx of min and updating it, time: O(n^2), space O(1) no additional allocs
for (i=0; i< SIZE; i++) { //
temp = hex_color_codes[i];
min = i;
for (j=i+1; j< SIZE; j++) {
if (hex_color_codes[min] > hex_color_codes[j]) {
min = j;
}
}
hex_color_codes[i] = hex_color_codes[min];
hex_color_codes[min] = temp;
}
print_arr(hex_color_codes);
return EXIT_SUCCESS;
}