Active Visual Scaffolding by Charles Kelemen and Eugene Turk


window.highlight(0, new Color(200,200,100), 50); window.redraw(); for (int firstuns=1; firstuns < n; firstuns++) { // inv: a[0.. firstuns-1] is sorted if (a[firstuns - 1] > a[firstuns]) { //shift some of a [0.. firstuns-1] back to make a place temp=a[firstuns]; pothole=firstuns; //saved value in temp, //now potential hole at firstuns window.highlight(pothole, Color.white, 50); window.redraw(); do { pothole--; a[pothole+1] = a[pothole]; window.highlight(pothole+1, new Color(200,200,100), 0); window.highlight(pothole, Color.white, 50); window.redraw(); } while ((pothole>0) && (temp < a[pothole-1])); a[pothole] = temp; //found the right spot so put temp into it window.highlight(pothole, new Color(200,200,100), 50); window.redraw(); } //end if window.highlight(firstuns, new Color(200,200,100), 50); // inv: a[0.. firstuns] is sorted window.redraw(); } //end for }

To pvwtalk12