2014-09-04 182 views
-2

我一直在嘗試編寫一個程序來使用插入排序對鏈接列表進行排序,並且我找到的解決方案以迭代的方式執行,我們如何編寫遞歸算法?插入排序 - 鏈接列表 - 遞歸

ps。這不是一個分配問題。

+0

我通常會問你的問題是什麼,或者什麼的,但嚴重只是谷歌這有答案全部結束,其中許多與代碼。 – U2EF1 2014-09-04 04:25:29

+0

如果我沒有這樣做,那麼是無論如何,但它是堆棧溢出是不是它。一個不明的鏈接會有所幫助。 – 2014-09-04 04:33:21

回答

0
To insert a node n to a list L: 
    If L is empty, return n 
    Split L into L0 (the head, first item in L) and LR (the rest) 
    If n.data < L0.data then insert n at the head of L and return L 
    insert n into LR and return L