数据结构算法4-简单选择排序

#include<bits/stdc++.h>
using namespace std;
int buf[8] = {49,38,65,97,76,13,27,49};
void selectSort(int buf[],int n){
	int i,j,k;
	int temp;
	for(i=0;i<n;i++){
		k = i;
		for(j=i+1;j<n;j++){
			if(buf[j]<buf[k]) {
				k = j;
			}	
		}//找到最小值
		temp = buf[i];
		buf[i] = buf[k];
		buf[k] = temp; 
	}
}
int main(){
	selectSort(buf,8);
	for(int i=0;i<8;i++){
		printf("%d ",buf[i]);
	}
	printf("\n");
}

猜你喜欢

转载自blog.csdn.net/weixin_37762592/article/details/88776532
今日推荐