Friday, 7 July 2017

C++ program of bubble sort

//Program starts

#include<iostream>

using namespace std;

int main()
{
int a,b,arr[a];

cout<<"How many indexes you wants to create : ";
cin>>a;
cout<<"Enter data in dissorted form "<<endl;
int m;
for(int y=0;y<=a-1;y++)
{
cin>>arr[y];
}


for(int i=0;i<=a-2;i++)
{
for(int j=0;j<=a-2-i;j++)
{
if(arr[j]>arr[j+1])
{
m=arr[j];
arr[j]=arr[j+1];
arr[j+1]=m;
}

}
}
cout<<"\n Data in sorted form \n\n";
for(int k=0;k<=a-1;k++)
{
cout<<"Data at Index ["<<k <<"] = "<<arr[k]<<endl;
}


}
/Program ends

OUTPUT:
Share:

0 comments:

Post a Comment