选择排序

选择排序:

#include <stdio.h>

void SelectSort(int A[], int n)
{
	int i = 0;
	for(i=0;i<n-1;i++)
	{
		int min = A[i];
		int key = i;
		//int j = i;
		for(int j=i;j<n;j++)
		{
			if(A[j] < min)
			{
				min = A[j];
				key = j;
			}
		}

		A[key] = A[i];
		A[i] = min;	
	}
}

void printMatrix(int A[], int n)
{
	for(int i=0;i<n;i++)
		printf("%d",A[i]);
}

int main(void)
{
	int A[] = {6,5,4,9,8,1};
	SelectSort(A,6);
	printMatrix(A,6);
	return 0;
}
 

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