Next:
Looping Control Structure
Up:
CS101 Lecture 5
Previous:
Approach 1: Compare consecutive
Approach 2: Compare last with all above
Work this method by hand.
Summarizing:
Start from top (i = 1) and repeatedly compare (and swap if needed)
with
(not
like last time!) until
. (
this pushes biggest number to bottom of array
).
Start again from top (i = 1) and repeatedly compare (and swap if needed)
with
until
. (
this pushes second biggest number to bottom-1 of array
).
...
(continue like this, how many times?)
We need to understand ``repeated'' execution of same statements (called
LOOPS
). Then we can write above cleanly!
G. Sivakumar 2000-08-13