C++ program in binary search bubble sort program

 

#include <iostream>
using namespace std;

int main()

{

int n,i,arr[50],j,temp;

cout<<"enter size of array";

cin>>n;

cout<<"enter elements of array";

for(i=0;i<n;i++)

{
cin>>arr[i];

}
cout<<"sorting using bubble sort";

for(i=0;i<(n-1);i++)

{
for(j=0;j<(n-i-1);j++)

{
if(arr[j]>arr[j+1])

{temp=arr[j];

arr[j]=arr[j+1];

arr[j+1]=temp;

}
}
}
cout<<"sorted array is";

for(i=0;i<n;i++)
{

cout<<arr[i];

}
return 0;
}

Comments

Popular Posts