TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: CHRISTIAN FELDE
from: KURT KUZBA
date: 1998-01-26 02:52:00
subject: sort.cpp

CF>   when I try to run it, there's no output
   Try it like this. I increased the modularity of it and made
   a few other changes to increase the readability and utility.
   The output buffer may require that you use the flush in order
   to force the output to appear on your screen.
// bblsort.cpp
#include 
void Swap(int &A, int &B)
{
   int iSwap = A;
   A = B;
   B = iSwap;
}
void BubbleSort(int *array, int limit, int reverse = 0)
{
   int sorting, element, next;
      do {
         sorting = 0;
         for (element = limit - 1 ; element > 0; element--)
         {
            next = element - 1;
            if(
               (array[element] < array[next] && !reverse)
               || (array[element] > array[next] && reverse)
            )
            {
               Swap(array[element], array[next]);
               sorting = 1;
            }
         }
      }  while(sorting);
}
void main()
{
      const int MAX = 10;
      int table[MAX];
      int i;
      cout << "\n\n\tThis program demostrates sorting array "
          << "elements into\n\tascending/descending order\n\n"
          << "\tEnter ten integers:\n";
      for (i = 0; i < MAX; i++)
      {
            cout << (i + 1) << ".: " << flush;
            cin >> table[i];
            cout << flush;
      }
      cout << "\n\n\tThe unsorted array is: ";
      for (i = 0; i < MAX; i++)
         cout << table[i] << " " << flush;
      BubbleSort(table, MAX);
      cout << "\n\n\tThe ascending sorted array is: ";
      for (i = 0; i < MAX; i++)
         cout << table[i] << " " << flush;
      BubbleSort(table, MAX, 1);
      cout << "\n\n\tThe descending sorted array is: ";
      for (i = 0; i < MAX; i++)
         cout << table[i] << " " << flush;
      cout << endl;
}
> ] Remain calm and think. I will help you. - Kwai Chang CPUfan.
---
---------------
* Origin: *YOPS ]I[* 3.1 GIG * RA/FD/FE RADist * Milwaukee, WI (1:154/750)

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