首页 > 代码库 > 编程题之--链表反置

编程题之--链表反置

  对链表进行反置。例如:

  [1] -> [2] -> [3] -> [null]

变成:

  [3] -> [2] -> [1] -> [null]

自己思考的解法如下:

[null] [1] -> [2] -> [3] -> [null]
(p) (c) (n)
[null] <- [1] [2] -> [3] -> [null]
(p) (c) (n)

-------------------------------------

[null] <- [1] [2] -> [3] -> [null]
(p) (c) (n)
[null] <- [1] <- [2] [3] -> [null]
(p) (c) (n)

-------------------------------------

[null] <- [1] <- [2] [3] -> [null]
(p) (c) (n)
[null] <- [1] <- [2] <- [3] [null]
(p) (c) (n)

未完待续。。。

编程题之--链表反置