TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: ALL
from: MICHAEL RATHBURN
date: 1998-01-12 18:41:00
subject: sort algorithm

Hi All , hope you are having a nice day
Can someone explain how this sort works I have tried to follow it but I
just get confused.
/* (SORT.CPP)
/* **********************************************************
*        sort.cpp                                                             
                                   *
*        Ian M Wilks                10/4/94                                   
                                     *
********************************************************** */
#include 
void main()
{
        const int MAX = 10;
        int table[MAX];
        cout << "\n\n\tThis program demonstrates sorting array "
                 << "elements into\n\tdescending order\n\n"
                 << "\tEnter ten integers: ";
        for(int i = 0; i < MAX; i++)
                cin >> table[i];
        cout << "\n\n\tThe unsorted array is: ";
        for(i = 0; i < MAX; i++)
                cout << table[i] << "  ";
        //sort
        int temp, test = 0;
this is the confusing part :-
        while(test == 0)
        {
                test = 1;
                for (i = 0; i < (MAX - 1); i++)
                {
                        if (table[i] < table[i + 1])
                        {
                                temp = table[i];
                                table[i] = table[ i + 1];
                                table[i + 1] = temp;
                                test = 0;
                        }
                }
        }
        cout << "\n\n\tThe sorted array is: ";
        for(i = 0; i < MAX; i++)
                cout << table[i] << "  ";
}*/
 -=> Yours sincerely, Michael Rathburn <=-
... "I drink beer, but not from bottles", Tom said cannily.
~~~ Tag-O-Matic V.13 ! I recognise the Green Frog.
--- Terminate 5.00/Pro 
---------------
* Origin: Have you ever been TERMINATEd ? (2:250/124.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™.