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)
|