-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathARRAY_SortingAlgorithms_lab2.c
64 lines (60 loc) · 1.18 KB
/
ARRAY_SortingAlgorithms_lab2.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
59
60
61
62
63
64
#include<stdlib.h>
#include<stdio.h>
int inputArr[25], size, i, j;
void bubbleSort(int a[], int n)
{
int temp;
for(i=0;i<n-1;i++)
{
for(j=0;j<n-i-1;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
printf("\nArray sorted in Ascending Order using Bubble Sort: \n");
for(i=0;i<n;i++)
{
printf("%d\t",a[i]);
}
}
void selectionSort(int d[], int n)
{
int least,temp;
for(i=0;i<n;i++)
{
least=i;
for(j=i+1;j<n;j++)
{
if(d[j]<d[least])
{
least=j;
}
}
temp=d[least];
d[i]=d[least];
d[least]=temp;
}
printf("\nArray sorted in Descending Order using Selection Sort: \n");
for(i=n-1;i>=0;i--)
{
printf("%d\t",d[i]);
}
}
void main()
{
system("cls");
printf("Enter the number of elements: ");
scanf("%d",&size);
printf("Enter %d elements: \n",size);
for(i=0;i<size;i++)
{
scanf("%d",&inputArr[i]);
}
bubbleSort(inputArr,size);
selectionSort(inputArr,size);
}