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

Bubble Sort

This document describes an implementation of bubble sort in C. It defines a bubble() function that takes an integer array and size as arguments. The function iterates through the array twice, swapping adjacent elements if they are out of order. The main() function prompts the user to enter array elements, calls bubble() to sort them, and prints the sorted array.

Uploaded by

Someya Goel
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views1 page

Bubble Sort

This document describes an implementation of bubble sort in C. It defines a bubble() function that takes an integer array and size as arguments. The function iterates through the array twice, swapping adjacent elements if they are out of order. The main() function prompts the user to enter array elements, calls bubble() to sort them, and prints the sorted array.

Uploaded by

Someya Goel
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

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.

//Analysis of Algorithms
//Sorting Techniques - C Data Structures
//WACP to Iimplement Bubble Sort Technique.
//Program by:- GAURAV AKRANI.
//TESTED:- OK

#include<stdio.h>
#include<conio.h>
void bubble(int a[],int n)
{
int i,j,t;
for(i=n-2;i>=0;i--)
{
for(j=0;j<=i;j++)
{
if(a[j]>a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}

}//end for 1.
}//end function.

void main()
{
int a[100],n,i;
clrscr();
printf("\n\n Enter integer value for total no.s of elements to be sorted: ");
scanf("%d",&n);
for( i=0;i<=n-1;i++)
{ printf("\n\n Enter integer value for element no.%d : ",i+1);
scanf("%d",&a[i]);
}
bubble(a,n);
printf("\n\n Finally sorted array is: ");
for( i=0;i<=n-1;i++)
printf("%3d",a[i]);
} //end program.
/*

You might also like