标签:
#include "stdafx.h" #include <list> #include <iostream> #include <string> #include <memory> #include <vector> #include <map> #include <assert.h> using namespace std; #define BUFSIZ 100 int (&strToIntArr(string s,int &len))[BUFSIZ] { int arr[BUFSIZ]; int idx=0; char *pch = strtok(const_cast<char*>(s.c_str()),", "); while(pch!=NULL){ arr[idx++] = atoi(pch); pch = strtok(NULL,", "); } len=idx; return arr; } void insertSort(int (&arr)[BUFSIZ],int len) { if(len<2){ return; } int key,i; for(int j=1;j<len;j++){ key=arr[j]; i=j-1; while(i>-1 && arr[i]>key){ arr[i+1]=arr[i]; i=i-1; } arr[i+1]=key; } } int _tmain(int argc, _TCHAR* argv[]) { string input; cin>>input; int arr_len; int (&arr)[BUFSIZ] = strToIntArr(input,arr_len); insertSort(arr,arr_len); for(int i=0;i<arr_len;i++){ cout<<arr[i]<<endl; } system("pause"); return 0; }
标签:
原文地址:http://www.cnblogs.com/sky-view/p/5095298.html