View Single Post
Old 12-05-2004, 11:47 AM   #6 (permalink)
developer
 
Junior Techie

Join Date: Dec 2004

Posts: 88

developer

Default

Exchange sort analyses every element sequentially and compares it with the next. The element is exchanged if its smaller/greater.
Eg 4,7,2,9
first cycle, first time
4 with 7
Its smaller, therefore exchange it.
so 7,4,2,9
now we compare 4 and 2.
so 7,4,2,9
Now 2 and 9
so 7,4,9,2
In the next cycle we will compare only till the second last element.
The thing to be noted is that after each cycle the smallest item will become the last.

7,4,9,2
7,9,4,2

9,7,4,2

Therefore the array is sorted.
There r many other types of sorting techniques.
__________________
Somewhere I Belong...
developer is offline