-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelection Sort.c
More file actions
76 lines (47 loc) · 873 Bytes
/
Selection Sort.c
File metadata and controls
76 lines (47 loc) · 873 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <stdio.h>
int main()
{
//insertion sort
int a[20],data[20],min,temp;
int i,j,k,n;
printf("Enter the number of arrays\n");
scanf("%d",&n);
printf("Enter the array\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(j=1;j<n;j++)
{
temp=a[j];
for(i=j;i>0&&temp<a[i-1];i--)
a[i]=a[i-1];
a[i]=temp;
}
for(i=0;i<n;i++)
printf("%d",a[i]);
printf("\n");
//selection sort
int a[20],data[20],min,temp;
int i,j,k,n;
printf("Enter the number of arrays\n");
scanf("%d",&n);
printf("Enter the array\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
min=a[i];
if(a[j]<min)
{
min=a[j];
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
for(i=0;i<n;i++)
printf("%d",a[i]);
printf("\n");
}