-
Notifications
You must be signed in to change notification settings - Fork 0
/
selectionSort.c
58 lines (42 loc) · 1004 Bytes
/
selectionSort.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
//Program to Implemet Selection Sort
//Completed...
#include<stdio.h>
int arr[10] = {12,98,11,87,10,97,24, 14, 56, 42};
int i, n = sizeof(arr)/sizeof(arr[0]);
void display(){
printf("The Sorted Array is: ");
for (i = 0; i < n; i++){
printf("%d ", arr[i]);
}
}
void scanElements(){
for (i = 0; i < n; i++){
scanf("%d", &arr[i]);
}
printf("\n");
}
void selectionSort(){
int j, min;
int temp;
/*printf("Enter 8 Elements: ");
scanElements(); */
for(i = 0; i < n-1 ; i++) //Probably mistake is over here.................
{
min = i;
for(j = i+1; j < n; j++){
if(arr[j]< arr[min]){
min = j;
}
}
//Here min variable will be having index of smallest Element
if(min != i){
temp = arr[i];
arr[i] = arr[min];
arr[min] = temp;
}
}
}
int main(){
selectionSort();
display();
}