// LineList.cpp : selectSort.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
void selectSort(int iArray[],int n);
int _tmain(int argc, _TCHAR* argv[])
{
int *arrayTest= new int[5];
arrayTest[0]=55;
arrayTest[1]=8;
arrayTest[2]=1;
arrayTest[3]=122;
arrayTest[4]=42;
cout << "Status before sorting: "<<endl;
for(int i=0;i<5;i++)
{
cout << arrayTest[i]<<" " <<endl;
}
selectSort(arrayTest,5);
cout << "Status after sorting: " <<endl;
for(int i=0;i<5;i++)
{
cout << arrayTest[i]<<" " <<endl;
}
getchar();
return 0;
}
void selectSort(int iArray[],int n)
{
int k;// To locate the smallest number in the specified array.
int temp;// For exchanging number.
for(int i=0;i<n;i++)
{
k=i;
for(int j=i+1;j<n;j++)
{
if(iArray[j]<iArray[k])
{
temp=iArray[k];
iArray[k]=iArray[j];
iArray[j]=temp;
}
}
}
}