Bubble Sort PDF
Bubble Sort PDF
h>
2 #include <stdlib.h>
3 void swap(int *xp, int *yp)
4 {
5 int temp = *xp;
6 *xp = *yp;
7 *yp = temp;
8 }
9 int main()
10 {
11 int n;
12 printf("Enter number of elements: ");
13 scanf("%d",&n);
14 int arr[n],i,j;
15 for(i=0;i<n;i++)
16 scanf("%d",&arr[i]);
17
18 //bubble sort logic
19 for(i=1;i<n;i++){
20 for(j=0;j<n-i;j++){
21 if(arr[j]>arr[j+1])
22 swap(&arr[j],&arr[j+1]);
23 }
24 }
25
26 for(i=0;i<n;i++)
27 printf("%d\t",arr[i]);
28 return 0;
29 }
30