-
Notifications
You must be signed in to change notification settings - Fork 0
/
BubbleSortInC.c
56 lines (48 loc) · 1.02 KB
/
BubbleSortInC.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
#include<stdio.h>
void printTheSortedArray(int arr[],int n)
{
printf("the sorted array is-------\n");
for(int i = 0; i<n; i++)
{
printf("%d ",arr[i]);
}
}
void swap(int* i, int* j)
{
int temp = *i;
*i = *j;
*j = temp;
}
void BubbleSort(int arr[],int n)
{
for(int i = 0; i<n-1; i++)
{
for(int j=0 ; j<n-i-1; j++)
{
if(arr[j] > arr[j+1])
{
swap(&arr[j],&arr[j+1]);
}
}
}
}
int main()
{
int array[100],n;
printf("enter the size of array: ");
scanf("%d",&n);
printf("the size of the array %d\n",n );
printf("enter the element of array:-------\n");
for(int i = 0; i<n; i++)
{
printf("array[%d] = ",i);
scanf("%d",&array[i]);
}
printf("the array is:--------\n");
for(int i = 0; i<n; i++)
{
printf("array[%d] = %d\n",i,array[i]);
}
BubbleSort(array,n);
printTheSortedArray(array,n);
}