0% found this document useful (0 votes)
35 views1 page

Bubble Sort PDF

The document contains code for bubble sort algorithm that sorts elements in an array in ascending order by repeatedly swapping adjacent elements that are in wrong order. The code takes input size of array, elements of array, implements bubble sort logic by swapping adjacent elements in wrong order and prints sorted array.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views1 page

Bubble Sort PDF

The document contains code for bubble sort algorithm that sorts elements in an array in ascending order by repeatedly swapping adjacent elements that are in wrong order. The code takes input size of array, elements of array, implements bubble sort logic by swapping adjacent elements in wrong order and prints sorted array.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

1 #include <stdio.

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

You might also like