-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathBubbleSort.c
45 lines (41 loc) · 1.18 KB
/
BubbleSort.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
/******************************************************
* File : BubbleSort.c
* Description : C Program to implement Bubble Sorting Algorithm
* Author : Sarju S
* Version : 1.0
* Date : 22/06/2021
* ***************************************************/
#include<stdio.h>
int main(){
int myArray[10],i,j,limit,temp;
//Read the size of the Array
printf("\nEnter the size of the array(Maximum is limited to 10)");
scanf("%d",&limit);
//Read the the Array
printf("\nEnter the %d elements:",limit);
for(i=0;i<limit;i++){
scanf("%d",&myArray[i]);
}
//print the Array
printf("\nThe Given Array Before Sort:");
for(i=0;i<limit;i++){
printf("%d\t",myArray[i]);
}
// Bubble Sort
for(i=0;i<limit-1;i++){
for(j=0;j<limit-i-1;j++){
if(myArray[j]>myArray[j+1]){
//Swapping
temp = myArray[j];
myArray[j] = myArray[j+1];
myArray[j+1]=temp;
}
}
}
//print the Array
printf("\nThe Given Array After Sort:");
for(i=0;i<limit;i++){
printf("%d\t",myArray[i]);
}
return 0;
}