Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Fast way to sort moves in movelist ? - Bubble Sort

Author: KarinsDad

Date: 11:03:49 10/18/99

Go up one level in this thread


On October 16, 1999 at 07:59:32, leonid wrote:

[snip]
>
>If somebogy will mention what is the "bubble sort" it will be appreciated.
>
>Leonid.

A bubble sort partially sorts with each pass. Hence, the passes for sorting the
characters AECFDB are:

1  2  3  4  5  6

A  A  A  A  A  A
E  C  C  C  B  B
C  E  D  B  C  C
F  D  B  D  D  D
D  B  E  E  E  E
B  F  F  F  F  F

Each field is compared with the next field and if larger, it is exchanged. And,
optimizations can be done such as only searching through to the last exchange
(such as for pass 4, you only need to do 3 comparisons since in pass 3, the E
got placed into the 5th location). Note: in the example above, A does not get
checked against B until the 6th pass, so although the data is actually sorted in
5 passes, the 6th pass verifies it.

Bubble sorts are very inefficient since they make so many comparisons and
exchanges in memory, however, they are easy to code, so I often use them to do a
sort when I do not know if I need to actually sort. If I find out I need to
sort, I eventually replace the bubble sort with a more optimized sort.

I'm sure Dann has a web page to point you to code.

KarinsDad :)



This page took 0.01 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.