void Adjust(int T[]int s)
{ //選得最小關鍵字記錄後從葉到根調整敗者樹選下一個最小關鍵字
//沿從葉子結點R[s]到根結點T[]的路徑調整敗者樹
t=(s+k)/; //T[t]是R[s]的雙親結點
while(t>)
{ if(R[s]key>R[T[t]]key) s<>T[t]; //s指示新的勝者
t=t/;
}//while
T[]=s;
}//Adjust
void CreateLoserTree(int T[])
{ //建立敗者樹已知R[]到R[k]為完全二叉樹T的葉子結點存有k個關鍵字沿
//從葉子到根的k條路徑將T調整為敗者樹
R[k]key=MINKEY; //MINKEY是最小關鍵字
for(i=;i<k;i++) T[i]=k; //設置T中敗者的初值
//依次從R[k]R[k]…R[]出發調整敗者
for(i=k;k>=;i) Adjust(Ti);
}//CreateLoserTree
[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
From:http://tw.wingwit.com/Article/program/sjjg/201311/23169.html