【文章內(nèi)容簡(jiǎn)介】
11. end if12. A[p..r]← B[p..r]用C語言實(shí)現(xiàn)上述算法并上機(jī)通過。選做題:用遞歸方法(分治法)實(shí)現(xiàn)自底向上合并排序法。習(xí)題四(工程名為10源程序名為104)參考下列程序,對(duì)習(xí)題一和習(xí)題三的程序作適當(dāng)修改。通過上機(jī)運(yùn)行,實(shí)驗(yàn)測(cè)評(píng)二種排序算法運(yùn)行效率,以期在理論和實(shí)踐上得出一致的結(jié)論。⑴選擇排序算法修改include include include include include define N 65536*2void Selection(short[],int)。void main(){ short A[N+1]。srand(time(NULL))。 for(int i=1。i=N。i++)A[i]=rand()%10000。 time_t t1,t2。 struct tm *pt。 time(amp。t1)。pt=gmtime(amp。t1)。 coutsetfill(39。039。)。 cout排序開始時(shí)間:。 coutsetw(2)(pttm_hour+8)%24:setw(2)pttm_min:setw(2)pttm_secendl。 coutSelectionSort排序中flush。 for(i=1。i=N1。i++){ if(i%2048==0)cout.flush。Selection(A,i)。 } coutendl排序結(jié)束時(shí)間:。 time(amp。t2)。pt=gmtime(amp。t2)。 coutsetw(2)(pttm_hour+8)%24:setw(2)pttm_min:setw(2)pttm_secendl。 cout排序耗費(fèi)時(shí)間=t2t1endl。 getch()。}⑵歸并排序法修改include include include include include const int N=65536*2。void BottomUpSort(short[],int)。void Merg(short[],int,int,int)。void main(){ short A[N+1]。 srand(time(NULL))。 for(int i=1。i=N。i++)A[i]=rand()%1000。 time_t t1,t2。 struct tm *pt。 time(amp。t1)。pt=gmtime(amp。t1)。 coutsetfill(39。039。)。 cout排序開始時(shí)間:。 coutsetw(2)(pttm_hour+8)%24:setw(2)pttm_min:setw(2)pttm_secendl。 coutMergeSort排序中flush。 BottomUpSort(A,N)。 time(amp。t2)。pt=gmtime(amp。t2)。 coutendl排序結(jié)束時(shí)間:。