-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsortingalgos.c
More file actions
48 lines (37 loc) · 966 Bytes
/
sortingalgos.c
File metadata and controls
48 lines (37 loc) · 966 Bytes
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
double* BubbleSort(double* numbers, int count)
{
double change_val;
for (int i = 0; i < count; i++)
{
for (int j = 0; j < count - i - 1; j++)
{
if (numbers[j] > numbers[j + 1])
{
change_val = numbers[j];
numbers[j] = numbers[j + 1];
numbers[j + 1] = change_val;
}
}
}
return numbers;
}
double* SelectionSort(double* numbers, int count)
{
double change_val;
int max_index = 0;
for (int i = 0; i < count; i++)
{
for (int j = 0; j < count - i; j++)
{
if (numbers[j] > numbers[max_index])
{
max_index = j;
}
}
change_val = numbers[max_index];
numbers[max_index] = numbers[count - i - 1];
numbers[count - i - 1] = change_val;
max_index = 0;
}
return numbers;
}