标签:选择排序
#include<iostream.h> #define SIZE 8 typedef int SqList[SIZE]; void SelectSort(SqList &Sq,int n)//13,38,65,97,76,27,49,49 { int temp=0; for(int i=0;i<n;++i)//选择的趟数 { for(int j=i;j<n;++j)//其实只比较了n-i次 { if(Sq[i]>Sq[j+1])//选择i趟中的一个数和剩下n-i趟中的所有数比较 { temp=Sq[j+1]; Sq[j+1]=Sq[i]; Sq[i]=temp; } } } } void main() { SqList Sq={49,38,65,97,76,13,27,49}; cout<<"未排序前:"; for(int i=0;i<SIZE;++i) { cout<<Sq[i]<<" "; } cout<<endl; SelectSort(Sq,SIZE-1); cout<<"已排序后:"; for(i=0;i<SIZE;++i) { cout<<Sq[i]<<" "; } cout<<endl; } <img src="http://img.blog.csdn.net/20150618015653766?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvemhvdTc1MzA5OTk0Mw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
标签:选择排序
原文地址:http://blog.csdn.net/zhou753099943/article/details/46541487