#include<iostream> #include<vector> using namespace std; #define INF 1000 int zhao_zuixiaozhi(vector<int> &ary); int COUT_xulie(vector<int> &ary) { int jishu_number=0; int now_min_numver; int now_min; vector<int>ary_temp=ary; now_min_numver=zhao_zuixiaozhi(ary_temp); now_min=ary_temp[now_min_numver]; ary_temp[now_min_numver]=INF; cout<<now_min; jishu_number++; int next_min_number; int next_min; int ary_size=ary_temp.size(); while(jishu_number<ary_size) { next_min_number=zhao_zuixiaozhi(ary_temp); next_min=ary_temp[next_min_number]; if(next_min_number<now_min_numver) { cout<<‘,‘<<next_min; jishu_number++; } else { cout<<endl; cout<<next_min; jishu_number++; now_min=next_min; now_min_numver=next_min_number; } ary_temp[next_min_number]=INF; } return 1; } int zhao_zuixiaozhi(vector<int> &ary) { vector<int>::iterator i_beging,i_end; int min_result,min_number,i=0; min_result=ary[0]; min_number=0; for(i=0;i!=(ary.size());i++) { if(ary[i]<min_result) { min_result=ary[i]; min_number=i; } } return min_number; } int main() { vector<int> ary; ary.push_back(1); ary.push_back(2); ary.push_back(5); ary.push_back(8); ary.push_back(10); ary.push_back(4); ary.push_back(3); ary.push_back(6); ary.push_back(9); ary.push_back(7); COUT_xulie(ary); //cout<<zhao_zuixiaozhi(ary)<<endl; //int a[10]={1,2,3}; //ary={1,2,8,10,4,3,6,9,7}; //COUT_xulie(ary); system("pause"); return 1; }
时间: 2024-10-12 21:30:53