DSA:Bubble Sort
class bubblesort
{
int i,j,n=0,a[];
public bubblesort(int max)
{
a=new int[max];
}
public void insert(int item)
{
a[n]=item;
n++;
}
public void display()
{
for(i=0;i
System.out.print(a[i]+"\t");
}
public void sort()
{
for(i=0;i
{
for(j=0;j<(n-i-1);j++)
{
if(a[j]>a[j+1])
{
int temp=a[j+1];
a[j+1]=a[j];
a[j]=temp;
}
}
}
}
}
No comments:
Post a Comment