
October 26th, 2004, 02:27 AM
|
 |
Contributing User
|
|
Join Date: Dec 2003
Location: Malaysia
Posts: 160
  
Time spent in forums: 1 Day 6 h 20 m 9 sec
Reputation Power: 8
|
|
|
Comb Sort Algorithm Enquiry
I have a problem here. The question is like this:
Write a comb sort function.Comb sort is a modified bubble sort routine that has a reducing variable comparison gap. A standard bubble sort has a comparison gap of 1 ie comparing with the nest elements that makes it very slow. The comb sort has a comparison gap that starts with the length of the list divided by 1.3 and reducing by a factor of 1.3 for every pass until it reaches 1.
My algorithm is like below:
Quote:
VAR list_length,pass,compared_position,compared_var,first_var
list_length= GET List length
pass=list_length / 1.3
WHILE pass < 1
compared_position=round(pass)
GET compared_var at compared_position
GET first_var in the list
IF compared_var <= first_var
PUT compared_var ahead first_var
END IF
pass=pass/1.3
LOOP |
I don't know whether my logic is correct or not. Any comment , suggestion and correction are very much appreciated. Thankz in advance.
__________________
If you can dream it, you can create it; it you can believe it, you can become it. --Anon
|