Guest User

Untitled

a guest
Apr 19th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.10 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. //Function prototypes
  5. void selectionSort (int [], int);
  6. void showArray (const int [], int);
  7.  
  8. int main()
  9. {
  10.     //Defines an array with unsorted values
  11.     const int SIZE = 100;
  12.     int value [SIZE];
  13.  
  14.     //Display the values.
  15.     cout << "The unsorted values are \n";"
  16.     showArray(value, SIZE);
  17.  
  18.     //Sort the values
  19.     selectionSort(vaule, SIZE);
  20.  
  21.     //Display the values again.
  22.     cout << "The sorted values are \n";
  23.     showArray(value, SIZE);
  24.    
  25.     system ("pause");
  26.     return 0;
  27. }
  28.  
  29. void selectionSort (int array [], int size)
  30. {
  31.     int startScan, minIndex, minValue;
  32.  
  33.     for (startScan = 0; startScan < (size - 1); startScan++)
  34.     {
  35.         minIndex = startScan;
  36.         minValue = array[startScan];
  37.         for (int index = startScan +1; index < size; index++)
  38.         {
  39.             if (array[index] < minValue)
  40.             {
  41.                 minValue = array[index];
  42.                 minIndex = index;
  43.             }
  44.         }
  45.     array[minIndex] = array[startScan];
  46.     array[startScan] = minValue;
  47.     }
  48. }
  49.  
  50.  
  51. void showArray (const int array [], int size)
  52. {
  53.     for (int count = 0; count < size; count++)
  54.         cout << array[cout] << "  ";
  55.         cout << endl;
  56. }
Add Comment
Please, Sign In to add comment