Seraph
Now You've done it.......
- Joined
- Sep 26, 2003
- Messages
- 897
- Gender
- Male
- HSC
- N/A
take a look at this insertion sort
BEGIN MAINPROGRAM
INITIALISATION
set First to first position
set Last to last position
set PositionOfNext to Last 1
ENDINITIALISATION
WHILE PositionOfNext >= First
set Next to data at PositionOfNext
set Current to PositionOfNext
WHILE (Current < Last ) AND (Next > data at (Current + 1))
increment Current
set data at (Current 1) to data at Current
ENDWHILE
set data at Current to Next
decrement PositionOfNext
ENDWHILE
END MAINPROGRAM
I dont udnerstand this , ive desk checked it and im doing something wrong
here 0 3 5 2 9
When i used these numbers it starts at Pos 4 which is 2 , now its not Greater than 9 so nothing changes there so Then the Numbers 5 and 2 are checked
5 is greater than 2
SO , the data at that position Moves on top of the data at the next position!!!
it overlaps it! , no swap was made just an overlap
how does that work???
BEGIN MAINPROGRAM
INITIALISATION
set First to first position
set Last to last position
set PositionOfNext to Last 1
ENDINITIALISATION
WHILE PositionOfNext >= First
set Next to data at PositionOfNext
set Current to PositionOfNext
WHILE (Current < Last ) AND (Next > data at (Current + 1))
increment Current
set data at (Current 1) to data at Current
ENDWHILE
set data at Current to Next
decrement PositionOfNext
ENDWHILE
END MAINPROGRAM
I dont udnerstand this , ive desk checked it and im doing something wrong
here 0 3 5 2 9
When i used these numbers it starts at Pos 4 which is 2 , now its not Greater than 9 so nothing changes there so Then the Numbers 5 and 2 are checked
5 is greater than 2
SO , the data at that position Moves on top of the data at the next position!!!
it overlaps it! , no swap was made just an overlap
how does that work???