DSA:Insertion Sort
class insertionsort
{
int j,n=0,a[],key;
public insertionsort(int max)
{
a=new int[max];
}
public void insert(int item)
{
a[n]=item;
n++;
// System.out.println("Element"+a[n-1]+"INserted");
}
public void display()
{int i;
for(i=0;i
{
System.out.print(a[i]+"\t");
}
}
public void sort()
{
int k,i;
for(i=0;i
{
key=a[i];
for(j=(i-1);(j>-1)&&(key
{
a[j+1]=a[j];
}
a[j+1]=key;
}
}
}
No comments:
Post a Comment