[Alg10] Heapsort 的核心: restore 程序更正 [很重要]

3 views
Skip to first unread message

Shyong Jian Shyu

unread,
Apr 26, 2010, 4:54:16 AM4/26/10
to sj10-al...@googlegroups.com
Heapsort 的核心: restore 程序更正
// 課本及講義有誤, 請依下程式碼更正
void restore (int s, int t)
{ int i=s, j, tmp;
        while (i<=t/2)
{ if (data[2*i]<data[2*i+1])
j=2*i;
else
j=2*i+1;

                if (data[i]<data[j]) break;
                else
                {  // swap(data[i], data[j]);
                   tmp = data[i];
                   data[i] = data[j];
                   data[j] = tmp;
   
   i = j;
                }
}
}

Heapsort 和 Quicksort(遞迴+非遞迴)/Mergesort(遞迴+非遞迴)/Insertionsort 的
執行效能比較 為作業四, 預計 5/14 交!!
Reply all
Reply to author
Forward
0 new messages