單鏈表反轉

2021-10-01 17:23:07 字數 952 閱讀 7102

到現在還不是特別懂,看別人的**找的。以後還需要繼續回來檢視這個鍊錶反轉。

#include#include#include#include #include#include #includeusing namespace std;

typedef struct listnode

}listnode, *linklist;

struct listnode *create(int n) //鍊錶建立函式

tail->next = null;

//cout << "鍊錶建立完畢!!!" << endl;

return head; //返回煉表頭指標

}void show(linklist head) //鍊錶輸出函式

cout << endl;

cout << "鍊錶輸出完畢!!!" << endl;

}class solution

return prev;

}};int main()

, b;

int *a1 = new int;

int *b1 = new int;

int *c1 = new int;

*a1 = 50;//源

*b1 = 80;

*c1 = 70;//

b1 = a1;//b1位址被a1替換

c1 = b1;//c1位址被a1替換 值為a1

//位址改變。值改變

//想要複製a1的內容 但是不改變a1的值//

鍊錶測試區

struct listnode *head,*l3;

head = create(7);

solution a2;

l3=a2.reverselist(head);

show(l3);

//print(l3);

}

單鏈表反轉

單鏈表反轉,可以用迴圈做,當然也可以遞迴 詳見 include includestruct node 3 1 4 6 2 1 1 3 4 6 2 2 4 1 3 6 2 3 6 4 1 3 2 4 2 6 4 1 3 5 迴圈反轉,即依次改動3個指標值,直到鍊錶反轉完成 比如,上面第 1 行到第 2...

反轉單鏈表

include stdafx.h include include using namespace std struct listnode typedef listnode plistnode typedef plistnode list list creatlist return head void...

單鏈表反轉

想起很早以前某次面試,面試官很嚴肅的要求我現場手寫單鏈表反轉的 哥虎軀一震,心想 不就需要要個臨時變數來記錄位址嗎,用得著這樣煞有介事?雖然在那之前我的確沒寫過這個程式,哈哈哈 當時我草草寫了十來行 面試官不等我完成,就直接拿過去開始問問題。不知道是不是因為抗壓能力不足,在面試官的不斷 盤問 下,哥...