TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: MICHAEL RATHBURN
from: ALEXEY MOKHOV
date: 1998-01-17 18:49:00
subject: sort algorithm

Hello, Michael!
12 Jan 98, Michael Rathburn wrote to All:
 :MR>         //sort
 :MR>         int temp, test = 0;
 :MR>         while(test == 0)
 :MR>         {
 :MR>                 test = 1;
 :MR>                 for (i = 0; i < (MAX - 1); i++)
 :MR>                 {
 :MR>                         if (table[i] < table[i + 1])
 :MR>                         {
 :MR>                                 temp = table[i];
 :MR>                                 table[i] = table[ i + 1];
 :MR>                                 table[i + 1] = temp;
 :MR>                                 test = 0;
 :MR>                         }
 :MR>                 }
 :MR>         }
You are looking through array (untill it is sorted = test==1 et the end of 
while-cycle), finding couples in wrong order and do position exchange for 
them. For example:
3 1 4 1 5 9
3 4 1 1 5 9    3 4 1 1 9 5
4 3 1 1 9 5    4 3 1 9 1 5    4 3 1 9 5 1
4 3 9 1 5 1    4 3 9 5 1 1
4 9 3 5 1 1    4 9 5 3 1 1
9 4 5 3 1 1    9 5 4 3 1 1
Not very effective but it is work.
Alexey
--- GoldED 3.00.Alpha4+
---------------
* Origin: St_1, St.Petersburg Russia (2:5030/155.19)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.