-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsort_in_c.c
53 lines (43 loc) · 796 Bytes
/
sort_in_c.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
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <inttypes.h>
const int SZ = 6;
void dbg_print(uint16_t* pArr)
{
for(int i=0; i<SZ; i++)
{
printf("%lu \t", pArr[i]);
}
printf("\n\r");
}
void sort(uint16_t* pArr)
{
uint16_t tmp = 0;
// take one element
for (int i = 0; i < SZ-1; i++)
{
for (int j = i+1; j < SZ; j++)
{
if( pArr[i] <= pArr[j])
{
// do nothing
}
else
{
tmp = pArr[i];
pArr[i] = pArr[j];
pArr[j] = tmp;
}
}
}
}
int main()
{
uint16_t arr[] = {4,7,2,0,3,9};
dbg_print(arr);
sort(arr);
dbg_print(arr);
return 0;
}