1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
//includers
#include <iostream>
#include <iomanip>
//using name space
using namespace std;
int main()
{
//variable in arrays
const int ISIZE = 7;
//Array A
int A[ISIZE] = { 88,75,71,31,55,98,89 };
selectionSort(A, ISIZE);
//Array B
const int B[ISIZE] = { 88,75,71,31,55,98,89 };
//print
system("pause");
return 0;
}
void selectionSort(int A[], int ISIZE) //Ascending
{
int startScan, minIndex, minValue;
for (startScan = 0; startScan < (ISIZE - 1); startScan++)
{
minIndex = startScan;
minValue = A[startScan];
for (int index = startScan + 1; index < ISIZE; index++)
{
for (int i = 0; i < ISIZE; i++)
{
cout << "Array[" << i << "] => " << A << endl;
}
if (A[index] < minValue)
{
minValue = A[index];
minIndex = index;
}//if
}//for index
A[minIndex] = A[startScan];
A[startScan] = minValue;
}//for start scan
}//selectionsort
|