BubbleSort
It is an inplace and comparison based sorting techoique.
In this algorithm each element is compared to its next element if they and not 'n' corooct order then swap these data item go to the next element.
Algorithm of Bubble Sort
Bubblesort( a[Max],n)
This algo arrange the item of array in asscending order
a[Max]=a[0 to Max-1]
n= NO. of item in array
STEP 1. Start
STEP 2.for i=1 to n-1 do
(a){ for j=0 to n-1-i do
if (a[j]>a[j+1]) trhen
swap (a[j] and a[j+1] }
STEP 3. stop
Time Complexity
Total Comparesion=(n-1)+(n-2)+_ _ _+3+2+1
=N\2(a+l)
+n-1\2(n-1+1)
+(m-1)\2=
T
Program of Bubble Sort
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[20],n,i,j,i,team;
cout<<"enter the size of array:";
cin>>n;
cout<<"enter the array element:";
for(i=0; i<n; i++)
{
cin>>a[i];
}
for(i=1; i<n; i++)
{
for(j=0; j<n-1; j++)
{
if(a[j]<a[j+1])
{
team=a[j];
a[j]=a[j+1];
a[j+1]=team;
}
}
}
cout<<"array after bubble sort:";
for(i=0; i<n; i++)
{
cout<<" "<<a[i];
}
getch();
}
It is an inplace and comparison based sorting techoique.
In this algorithm each element is compared to its next element if they and not 'n' corooct order then swap these data item go to the next element.
Algorithm of Bubble Sort
Bubblesort( a[Max],n)
This algo arrange the item of array in asscending order
a[Max]=a[0 to Max-1]
n= NO. of item in array
STEP 1. Start
STEP 2.for i=1 to n-1 do
(a){ for j=0 to n-1-i do
if (a[j]>a[j+1]) trhen
swap (a[j] and a[j+1] }
STEP 3. stop
Time Complexity
Total Comparesion=(n-1)+(n-2)+_ _ _+3+2+1
=N\2(a+l)
+n-1\2(n-1+1)
+(m-1)\2=
T
Program of Bubble Sort
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[20],n,i,j,i,team;
cout<<"enter the size of array:";
cin>>n;
cout<<"enter the array element:";
for(i=0; i<n; i++)
{
cin>>a[i];
}
for(i=1; i<n; i++)
{
for(j=0; j<n-1; j++)
{
if(a[j]<a[j+1])
{
team=a[j];
a[j]=a[j+1];
a[j+1]=team;
}
}
}
cout<<"array after bubble sort:";
for(i=0; i<n; i++)
{
cout<<" "<<a[i];
}
getch();
}