Bubble Sort in C++

Google Advertisements

Prev Tutorial Next Tutorial

Bubble Sort Program in C++

Bubble sort is the simplest sorting algorithm. In this technique we follow given step to short given elements in increasing order.

Steps to Sort data

  • First compare First (previous) element with its next elements.
  • If next element is grater than previous element just ignore it.
  • If next element is smaller than previous element then interchange their position.
bubble sort program in c++

Advantage of Bubble short in C++

It is very simple and easy method to short elements.

Dis-Advantage of Bubble short in C++

It is time comsuming and slow process to short elements.

Bubble Sort Program in C++

	
#include<iostream.h>
#include<conio.h>
#include<dos.h>

void main()
{
int i,a[100],temp,j,no;
clrscr();
cout<<"How many no. do u want to insert: ";
cin>>no;
cout<<"\nEnter any"<<no<<"num in array \n";

for(i=0;i<no;i++)
{
cin>>a[i];
}
cout<<"\n\n\nData before sorting : ";
for(j=0;j<no;j++)
{
delay(200);
cout<<"  "<<a[j];
}
for(i=0;i<no;i++)
{
for(j=0;j<no-i-1;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
cout<<"\n\n\nData after sorting : ";
for(j=0;j<no;j++)
{
delay(200);
cout<<"   "<<a[j];
}
getch();
}

Output

	
How many no. do u want to insert: 8
Enter any 8  num in array
Data before sorting : 5 3 6 2 7 8 1 4 
Data after sorting : 1 2 3 4 5 6 7 8
sort elements in c++
Prev Tutorial Next Tutorial

Google Advertisements

Buy This Ad Space @$50 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 8076671483

Pure VPN Privide Lowest Price VPN Just @ $1.65. Per Month with Non Detected IP Lowest Price Non Detected IP VPN

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

Cloud computing is the on demand availability of computer system resources, especially data storage and computing power, without direct active management by the user. Cloud Computing Tutorial

College Projects Related to Java, AWT, C Projects for College, C++ Projects for College, Android Projects. Download Java C C++ Projects

Download Projects

Adsense Advertisements


Buy This ads Space 8076671483

Buy This Ad Space @$120 per Month, Ad Size 300X600 Contact on: hitesh.xc@gmail.com or 8076671483 Try this Keyword C++ Programs