package com.java.chapterThree;
public class SelectSortApp {
/**
* @param args
*/
public static void main(String[] args) {
int maxSize=100;
SelectSort selectSort=new SelectSort(maxSize);
selectSort.insert(77);
selectSort.insert(99);
selectSort.insert(44);
selectSort.insert(55);
selectSort.insert(22);
selectSort.insert(88);
selectSort.insert(11);
selectSort.insert(00);
selectSort.insert(66);
selectSort.insert(33);
selectSort.displayArray();
selectSort.SeleteMethodSort();
selectSort.displayArray();
}
}
class SelectSort{
private long a[];
private int nElems;
SelectSort(int n){
a=new long[n];
nElems=0;
}
public void displayArray(){
System.out.print("[");
for(int i=0;i<this.nElems;i++){
System.out.print(a[i]+" ");
}
System.out.println("]");
}
public void insert(int value){
a[nElems]=value;
nElems++;
}
public void swap(int one,int two){
long temp=a[one];
a[one]=a[two];
a[two]=temp;
}
public void SeleteMethodSort(){
int m,n,min;
for(m=0;m<nElems;m++)
{ min=m;
for(n=m+1;n<nElems;n++)
if(a[n]<a[min]){
min=n;
}
swap(m,min);
}
}
}