==#==#==#==

This area is going private -- but free...at Voltaire U., D.L.

Toward A Note Book Of Algorithms

Wallace Brindle / V.U. snaelrowen@internav.com

INSERTION-SORT(A) PSEUDOCODE C,L,&R pp 3

Insertion sort works by inserting each value into a previously sorted subset of the list.

Black is CLR Pseudocode. Red is JAVA.

1 for j 2 to length[A]

1 for (int index = 1; index < numbers.length; index++)

2 do key A[j] 8 Takes A[j] VALUE off of the “table,” or unsorted "cards,"

for insertion standard (a.k.a. key.)

2 int key = numbers[index];

3 .... Insert A[j] into sorted seq. A[1..j - 1].

4 i j - 1 8 Comparison variable INDEX POSITION i is INDEX POSITION j - 1 (to its left, if you will.)

4 int position = index;

5 while i > 0 and A[i] > key 8 As long as you don’t go further than the number of sorted cards, and the VALUE of the sorted card is greater than the (it’s always a VALUE) key...

5 while (position > 0 && numbers[position-1] > key)

6 do A[i + 1] A[i] 8 Make the VALUE of sorted

card + (index-ual sense) 1 be that of the VALUE of sorted card being looked at.

6 numbers[position] = numbers[position-1];

7 i i - 1 8 Sorted INDEX POSITION card is moved one to the left.

7 position-; 8 The "full" Java code version of above Java sectional notes parallel to Pseudocode did not compile, error messages...; back to DrBoa; to Dr. Boa's Lab......Pseudocode works fine though (Comp Sci Humor -- or IS IT! No, I think not, this is where the Memory Reliance Issue is "outed" -- one needs to have the Pseudocode "compile" in the head of the Comp Sci Guy/Gal -- "playing computer" -"Important Safety Tip, thanks Egon..." Lest anyone find yet another reason to presume I'm crazy; some parts or urstylistic modules of this page are self-satire; mmmm, but not sooo much, do you think? Can we loosen-up people...can we just pop a kinna sicle?..."I'm thinking 'yes'...[-(/?)-] There is a tiny interrogative in that line I can't quite neopunctualize...[...] Dr. Boa!!").

8 A[i + 1] key

8 numbers[position] = key;

The index j indicates the “current card” being inserted into the hand. Array elements A[1..j - 1] constitute the currently sorted hand.

Notes: Thursday, June 24, 1999 -- I Was Telling Jacques D. One Day About Pseudocode Sys/Style Dvlpd CL&R: I color-coded, added quasi-semi tie-in to Java real code too, &etc:::: Walla!!!! Didactic Wonderment(!) "Very nice...next!"