2 17單鏈表的排序

2021-10-03 08:42:15 字數 851 閱讀 5164

public

class

test

; node head =

create1

(arr)

;sort

(head)

;for

(node p=head.next;p!=null;p=p.next)

}//鍊錶的選擇排序

public

static

void

sort

(node head)}}

//傳入乙個節點p,找到p節點(包括p)往後所有節點中最小值節點將其在原表刪除並返回

public

static node getmin

(node p)

node minnode = p;

//維護當前鍊錶最小值節點

node q = p.next;

while

(q!=null)

q=q.next;

}//如果p就是最小值節點 直接返回

if(minnode==p)

//刪除最小值節點

node pre = p;

//尋找前驅節點

while

(pre.next!=minnode)

pre.next = minnode.next;

return minnode;

}//建立乙個單鏈表

public

static node create1

(int

arr)

return head;}}

class

node

}

單鏈表之排序單鏈表

package list public class sortedsinglylist extends singlylist 將values陣列中的所有物件按值大小插入 public sortedsinglylist t values 過載深拷貝,由單鏈表構建排序單鏈表 public sortedsi...

單鏈表的排序

這是前幾天hottey面試的乙個題目 不借助外部陣列,只對鍊錶本身進行操作來完成排序。我覺得甚有意思,便實現了乙個。程式 如下 include using namespace std template struct node 節點結構 template class slist 單鏈表結構 slist...

單鏈表的排序

歸併排序的一種比較快的排序,尤其在鍊錶中,在所有排序中是時間複雜度為nlog n 級別的有三種,分別為快速排序,堆排序和歸併排序,但是快速排序在單鏈表中沒有優勢 適合於雙向鍊錶 同樣堆排序在建堆和調整堆得過程對於單鏈表也是比較麻煩,這裡我們選取了歸併排序。歸併排序的概念和原理我就不介紹了,網上的相關...