將乙個單鏈表逆序

2021-05-01 07:03:28 字數 394 閱讀 7097

struct list_node

int data;

list_node* next;

};void reserve(list_node* phead)

} 測試程式:

list lt;

lt.phead = new list_node(0,0);

lt.phead->next = new list_node(1,0);

lt.phead->next->next = new list_node(2,0);

lt.phead->next->next->next = new list_node(3,0);

lt.reserve();

list_node * p = lt.phead;

while(p)

將兩個單鏈表合併成乙個有序單鏈表

3.10 4.將兩個單鏈表合併成乙個有序單鏈表 由於以前初學c 時所寫的 不堪入目,不符合規範性,完整性和魯棒性,於是今日重寫其核心演算法以警示自己。node merge node p1head,node p2head else return pmergedhead 思路 因為鍊錶可以由結點輕鬆構造...

將單鏈表的每K個結點逆序

簡單做法,直接使用棧儲存那k個結點,然後將這k個結點逆序後連線到鍊錶上去,只需要注意頭節點即可。高階解法直接對鍊錶進行處理,每一次記錄當前逆序分組的第乙個結點和最後乙個結點,也需要考慮頭節點 解法 使用棧 直接對鍊錶進行迭代 普通 public static node reverseknode1 n...

單鏈表逆序

include include typedef struct student student typedef struct list list,list list createlist void paixu list l 比較笨拙的一種方法 list reverse list l int main ...