package datestructure;
public class SelectsortApp
{
public static void main(String[] args)
{
int maxsize=100;
SelectsortArray selectarr;
selectarr=new SelectsortArray(maxsize);
selectarr.insert(23);
selectarr.insert(45);
selectarr.insert(12);
selectarr.insert(34);
selectarr.insert(3);
selectarr.insert(7);
selectarr.insert(98);
selectarr.insert(0);
selectarr.insert(56);
selectarr.display();
selectarr.selectsort();
selectarr.display();
}
}
//////////////////////////
package datestructure;
class SelectsortArray
{
private int[] a;
private int nElems;
public SelectsortArray(int maxsize)
{
a=new int[maxsize];
nElems=0;
}
public void insert(int value)
{
a[nElems]=value;
nElems++;
}
public void display()
{
for(int j=0;j<nElems;j++)
System.out.print(a[j]+" ");
System.out.println("");
}
public void selectsort()
{
int i,j,min;
for(j=0;j<nElems-1;j++)
{
min=j;
for(i=j+1;i<nElems;i++)
if(a[min]<a[i])
min=i;
swap(j,min);
}
}
public void swap(int j,int i)
{
int k=0;
k=a[j];
a[j]=a[i];
a[i]=k;
}
}