-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselection_sort.c
More file actions
40 lines (31 loc) · 811 Bytes
/
selection_sort.c
File metadata and controls
40 lines (31 loc) · 811 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
#include<stdio.h>
void selection_sort(int arr[], int len);
int main()
{
int arr[] = {5, 9, 3, 18, 7, 4, 15, 23, 11, 1};
int length = sizeof(arr)/sizeof(int);
selection_sort(arr, length);
getch();
return 0;
}
void selection_sort(int arr[], int len)
{
int i, j, temp;
for(i = 0; i < len - 1; i++)
{
for(j = i + 1; j < len; j++)
{
if(arr[i] > arr[j])
{
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
printf("\n\n");
for(i = 0; i < len; i++)
{
printf("%d ", arr[i]);
}
}