TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: MICHAEL RATHBURN
from: THIERRY MOURE
date: 1998-01-16 23:56:00
subject: Re: sort algorithm

Thierry is replying to Michael who replied to All on 12 Jan 98 06:41pm
 MR> Hi All , hope you are having a nice day
 MR> Can someone explain how this sort works I have tried to follow it but I
 MR> just get confused.
 MR> /* (SORT.CPP)
 MR> /* **********************************************************
 MR> *        sort.cpp
 MR>                                 *
 MR> *        Ian M Wilks                10/4/94
 MR>                                   *
 MR> ********************************************************** */
 MR> #include 
 MR> void main()
 MR> {
 MR>         const int MAX = 10;
 MR>         int table[MAX];
 MR>         cout << "\n\n\tThis program demonstrates sorting array "
 MR>                  << "elements into\n\tdescending order\n\n"
 MR>                  << "\tEnter ten integers: ";
 MR>         for(int i = 0; i < MAX; i++)
 MR>                 cin >> table[i];
 MR>         cout << "\n\n\tThe unsorted array is: ";
 MR>         for(i = 0; i < MAX; i++)
 MR>                 cout << table[i] << "  ";
 MR>         //sort
 MR>         int temp, test = 0;
 MR> this is the confusing part :-
 TM> I've added some comments
 MR>         while(test == 0)    //test  0 ??
 MR>         {
 MR>                 test = 1;   //evident !
 MR>                 for (i = 0; i < (MAX - 1); i++) // the unsorted array
 MR>                 {
 MR>                         if (table[i] < table[i + 1]) //test if <
 MR>                         {
 MR>                                 temp = table[i];  //swap table[i] &
 MR>                                 table[i] = table[ i + 1]; //table[i+1]
 MR>                                 table[i + 1] = temp; //with temporary
 MR>                                 test = 0;       //memory int
 MR>                         }
 MR>                 }
 MR>         }
 MR>         cout << "\n\n\tThe sorted array is: "; // display sorted array
 MR>         for(i = 0; i < MAX; i++)
 MR>                 cout << table[i] << "  ";
 MR> }*/
 TM> You can destroy the While (test ==0) & test=1, because you know exactly
     how many times you must execute the loop 'for (i=0  etc...).
     May be, you can use the sorting algorithm like Shell or quick.
 -=>> Yours sincerely, Michael Rathburn <=-
 MR> ... "I drink beer, but not from bottles", Tom said cannily.
 MR> ~~~ Tag-O-Matic V.13 ! I recognise the Green Frog.
 MR> --- Courtesy of Silver Xpress
Thierry Moure
 * Evaluation copy of Silver Xpress. Day # 1
--- via Silver Xpress V4.01 [NR]
---------------
MR> * Origin: Have you ever been TERMINATEd ? (2:250/124.19)
* Origin: Morte Lune, Toulouse, France (2:324/106)

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™.