1 /*************************************************************************2 > File name:31_sortarraymin.cpp3 > Author:juntaran4 > Mail: [email protected]5 > Created time:2016 September 02 Friday 11:10 42 Seconds6 ************************************************************************/7 8#include <stdio.h>9#include <string>Ten#include <bits/stdc++.h> One A using namespacestd; - - stringITOsintx) the { - return(x>9? ITOs (x/Ten) :"") +Char(%Ten+'0'); - } - + BOOLcmpConst void*a,Const void*b) - { + return(ITOs (a) + ITOs (b)) < (ITOs (b) +ITOs (a)); A } at - BOOLCompareintAintb) - { - return(ITOs (a) + ITOs (b)) < (ITOs (b) +ITOs (a)); - } - in stringPrintminnumber (int* Nums,intlength) - { to strings =""; + if(Nums==null | | length<=0) - returns; the //sort (nums, nums+length, CMP); *Qsort (nums, Length,sizeof(int), CMP); $ Panax Notoginseng for(inti =0; i < length; ++i) -s + =ITOs (Nums[i]); thecout << S <<Endl; + returns; A } the + intMain () - { $ intNums[] = {3, +,321}; $ intLength =3; - Printminnumber (nums, length); - the return 0; -}
The sword Offer31 the array into the smallest number.