Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- //Function prototypes
- void selectionSort (int [], int);
- void showArray (const int [], int);
- int main()
- {
- //Defines an array with unsorted values
- const int SIZE = 100;
- int value [SIZE];
- //Display the values.
- cout << "The unsorted values are \n";"
- showArray(value, SIZE);
- //Sort the values
- selectionSort(vaule, SIZE);
- //Display the values again.
- cout << "The sorted values are \n";
- showArray(value, SIZE);
- system ("pause");
- return 0;
- }
- void selectionSort (int array [], int size)
- {
- int startScan, minIndex, minValue;
- for (startScan = 0; startScan < (size - 1); startScan++)
- {
- minIndex = startScan;
- minValue = array[startScan];
- for (int index = startScan +1; index < size; index++)
- {
- if (array[index] < minValue)
- {
- minValue = array[index];
- minIndex = index;
- }
- }
- array[minIndex] = array[startScan];
- array[startScan] = minValue;
- }
- }
- void showArray (const int array [], int size)
- {
- for (int count = 0; count < size; count++)
- cout << array[cout] << " ";
- cout << endl;
- }
Add Comment
Please, Sign In to add comment