C++选择排序

//C++选择排序

#include <iostream>

using namespace std;

void SelectSort(int *pData, int Count)
{
	int iTemp;
	int iPos;
	for (int i = 0; i < Count - 1; i++)
	{
		iTemp = pData[i];
		iPos = i;
		for (int j = i + 1; j < Count; j++)
		{
			if (pData[j] < iTemp)
			{
				iTemp = pData[j];
				iPos = j;
			}
		}

		pData[iPos] = pData[i];
		pData[i] = iTemp;
	}
}

void main()
{
	int data[] = {10, 4, 6, 5, 8};
	SelectSort(data, sizeof(data) / sizeof(int));
	for (int i = 0; i < 5; i++)
	{
		cout << data[i] << " ";
	}
	cout << "\n";
}

你可能感兴趣的:(C++选择排序)