Download as rtf, pdf, or txt
Download as rtf, pdf, or txt
You are on page 1of 1

BUBBLE SORT IN ARRAY

Program:
//bubble sort in array
#include<iostream.h>
#include<stdlib.h>
#include<stdio.h>
void bubsort(int [],int);
int main()
{
system("cls");

int a[50],n,i,item,index;
cout<<" \n no. element u want"<<endl;
cin>>n;
cout<<"\n enter array element"<<endl;

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

cin>>a[i];
bubsort(a,n);
cout<<"\n the sorted is as shown below"<<endl;
for(i=0;i<n;i++)
cout<<a[i]<<endl;
return 0;
}
void bubsort(int a[],int size)
{
int temp,ctr=0;
for(int i=0;i<size;i++)
{
for(int j=0;j<size-1;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1] ;
a[j+1]=temp;
}

}
cout<<" \n array after sorting:"<<++ctr<<"-is \n";
for (int f=0;f<size;f++)
cout<<a[f]<<""<<endl;
}
}

You might also like