class InsertionSortAlgorithm extends SortAlgorithm {
    void sort(int item[]) throws Exception {
      for (int i = 1; i < item.length; i++) {
// SAVE THE ITH ELEMENT
	int ith = item[i];

// SHIFT ELEMENTS LARGER THAN THE ith DOWN
	int j = i-1;
        // j in list  && ith < item[j]
	while (j > -1 && ith < item[j]){
	  if (stopRequested) {
	    return;
	  }
	  item[j+1] = item[j];
	  j--;
	  pause(i, j);
	}
	j++;
// PUT THE ith ELEMENT IN THE AVAILABLE j POSITION
	item[j] = ith;
      }
    }
}


