voidInsertSort(vector<int>& nums){ int len=nums.size(); if(len==0 || len==1) return; int key=0; int j=0; for(int i=1;i<len;i++){ key=nums[i]; j=i; while((j>=1) && (nums[j-1]>key)){ nums[j]=nums[j-1]; j--; } nums[j]=key; } }
intmain(){ int tmp; vector<int> arr; cout<<"Please type the array you wat to sort:"<<endl; while(cin>>tmp){ arr.push_back(tmp); } InsertSort(arr); for(auto& x:arr){ cout<<x<<" "; } return0; }
voidmerge(vector<int>& nums, int l, int m, int r){ int len1=m-l+1, len2=r-m; vector<int> arr1(len1); vector<int> arr2(len2); int i=0,j=0; for(i=0;i<len1;i++){ arr1[i]=nums[l+i]; } for(j=0;j<len2;j++){ arr2[j]=nums[m+1+j]; } i=0; j=0; int len=r-l+1; int k=l;