-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBubble_sort.c
79 lines (73 loc) · 1.15 KB
/
Bubble_sort.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//Bubble_sort #include<stdio.h>
void scan(int a[])
{
int i;
for(i=0;i<5;i++)
{
scanf("%d",&a[i]);
}
}
void swap(int *a,int *b)
{
int temp;
temp=*a;
*a=*b;
*b=temp;
}
void ascen(int a[])
{
int i,j;
for(i=0;i<5;i++)
{
for(j=i+1;j<5;j++)
{
if(a[j]<a[i])
{
swap(&a[i],&a[j]);
}
}
}
printf("Ascending order is :-\n");
for(i=0;i<5;i++)
{
printf("%d\t",a[i]);
}
}
void des(int a[])
{
int i,j;
for(i=0;i<5;i++)
{
for(j=i+1;j<5;j++)
{
if(a[j]>a[i])
{
swap(&a[i],&a[j]);
}
}
}
printf("Descending order is :-\n");
for(i=0;i<5;i++)
{
printf("%d\t",a[i]);
}
}
void main()
{
int a[5],ch;
printf("enter 5 element in array\n");
scan(a);
printf("Enter\n1.Ascending oder\t2.Decending order\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
ascen(a);
break;
case 2:
des(a);
break;
default:
printf("enter correct choice");
}
}