ݷʱ : 2024/12/23 1:44:16һ µȫĶ
һλãҵλúͽarr[i-1]룬arr[0],arr[1],,arr[n-1]
α
template
type temp; int j;
for(int i=1;i<=currentsize-1;i++) {
temp=arr[i];j=i-1;
while(j>=0&&temp cout<<\\<<++num<<\Ϊ:\; for(int t=0;t num=0; } <3>۰ ۰Ļ˼룺nԪarr[0],arr[1],,arr[n-1]Уarr[0],arr[1],,arr[n-1]ѾźIJԪУڲarr[i]ʱ۰ҷѰarr[i]IJλá۰ֻ˳洢ṹʵ֡ α£ template type temp; int left,right; for(int i=1;i left=0;right=i-1;temp=arr[i]; while(left<=right)//Ҳλ { int mid=(left+right)/2; if(temp for(int k=i-1;k>=left;k--)//ƶ arr[k+1]=arr[k]; arr[left]=temp; cout<<\\<<++num<<\Ϊ:\; for(int t=0;t num=0; } <4>ð ðĻ˼ǣnԪءȶеһԪصĹؼarr[0]arr[1]бȽϡǰߴںߣнȻԵڶͬĴظ˹ֱڵԪءdz֮ΪһðݣؼԪƵһλãԪһҲλƶȻеڶǰn-1ԪؽͬIJʹйؼִδԪرƵarr[n-2]λán-1ðݾܰԪź α£ template int i=1; int finish=0;//0ʾûź while(i finish=1;//־Ϊ,ٶѾź for(int j=0;j swap(arr[j],arr[j+1]);//Ԫؽλ finish=0; }//־Ϊ,ʾ˷˽˵ûź i++; cout<<\\<<++num<<\Ϊ:\; for(int t=0;t num=0; } <5>ѡֱѡ ֱѡ㷨˼ǣ a)ʼʱiijʼֵΪ0 b)i c)arr[k]ԪеĵһԪأikarr[k]arr[i]ԪصλöԵ d)i=i+1ת b) α£ template void sortlist int k; for(int i=0;i<=currentsize-1;i++) { k=i; for(int j=i+1;j k=j;//k ָʾǰСߵλ if(k!=i)//СؼֵԪλòi swap(arr[i],arr[k]); cout<<\\<<++num<<\Ϊ:\; for(int t=0;t num=0; } <6> Quick Sortֱһƽܷdzõ 㷨˼ǣȡеijԪ(ȡһԪ)ΪոԪصĹؼִСΪӱ ӱԪصĹؼֶСڻԪصĹؼ֡ҲӱԪصĹؼֶڻڻԪصĹؼ֣Ԫӱм(ҲǸԪӦŵλ)ȻֱӱظʩĿֱеӱΪ1 α£ template void sortlist int i=low,j=high; type temp=arr[low];//ȡһλΪλ if(i { while(i while(i if(i if(i } arr[i]=temp;//Ԫؾλ cout<<\\<<++x<<\Ϊ:\; for(int t=0;t quicksort(low,i-1);//ݹп quicksort(i+1,high);//ݹп } } <7>ѺͶ̣ 㷨Ļ˼ǣ a.еԪأöѵĵ㷨γɳʼѡ b.ѶԪء c.ʣԪµγɶѡ d.ظִеbcֱԪر (1)ѵα£ template void sortlist {//µʹstartʼcurrentsize-1ΪֹӱΪ int i=start,j=2*i+1;//jΪi int tablesize=currentsize; type temp=arr[i]; while(j<=currentsize-1) { if(j else{arr[i]=arr[j];i=j;j=2*j+1; } } arr[i]=temp; }