/* * @(#)InsertSwapSortAlgorithm.java 1.0 99/09/19 * */ public class InsertSwapSortAlgorithm extends SortAlgorithm { /**** * A very simple and badly documented insertion sort algorithm * swaps place, whenever a 'local' minimum is detected... * (I know, usually InsertionSort does not write back to the same array, * but here it is required to be an in-place algorithm) * * Oliver M"oller Sept. 1999 ************************/ private void swap(int[] a, int i, int j){ int T = a[i]; a[i] = a[j]; a[j] = T; } public void sort(int a[]) throws Exception{ for(int ii=0; ii < a.length; ii++){ for(int jj=ii+1; jj < a.length; jj++){ ncmp_count++; if (a[jj] < a[ii]) swap(a,ii,jj); pause(ii,jj); if(stopRequested)return; } } finished = true; pause(); } }