# 归档 2015年1月

## C++单链表逆置的迭代实现与递归实现 作者是 在线疯狂 发布于 2015年1月31日 在 数据结构, 译林.

Implement the reversal of a singly linked list iteratively and recursively.

1) 迭代实现:

``````void reverse(Node*& head) {
Node* prev = NULL;
while (curr) {
Node ...``````

## 题目描述：

Reverse a linked list from position m to n. Do it in-place and in one-pass.

For example:
Given 1->2->3->4->5->NULL, m = 2 and n = 4,

return 1->4->3->2->5->NULL.

Note:
Given m, n satisfy the following condition:
1 ≤ m ≤ n ...

## 题目描述：

Given a singly linked list L: L0→L1→…→Ln-1→Ln,
reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…

You must do this in-place without altering the nodes' values.

For example,
Given {1,2,3,4}, reorder it to {1,4,2,3}.

## 题目描述：

Given a binary tree, return the preorder traversal of its nodes' values.

For example:

Given binary tree {1,#,2,3},

```   1
\
2
/
3```

return [1,2,3].

## 解题思路：

``````iterativePreorder(node)
parentStack ...``````

## 题目描述：

You are a traveling salesman. You have already heard a lot about how hard the problems of a traveling salesman can be. Luckily, the one you currently have seems easier.

There are M cities where you can sell products ...