Skip to content

Commit dc3cd02

Browse files
committed
Update chapTree.tex
Eliminate useless variable. node *pre is totally unused, why leave it there?
1 parent 60a44ba commit dc3cd02

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

C++/chapTree.tex

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,12 @@ \subsubsection{Morris中序遍历}
185185
public:
186186
vector<int> inorderTraversal(TreeNode *root) {
187187
vector<int> result;
188-
TreeNode *cur, *prev;
188+
TreeNode *cur;
189189

190190
cur = root;
191191
while (cur != nullptr) {
192192
if (cur->left == nullptr) {
193193
result.push_back(cur->val);
194-
prev = cur;
195194
cur = cur->right;
196195
} else {
197196
/* 查找前驱 */
@@ -201,12 +200,10 @@ \subsubsection{Morris中序遍历}
201200

202201
if (node->right == nullptr) { /* 还没线索化,则建立线索 */
203202
node->right = cur;
204-
/* prev = cur; 不能有这句,cur还没有被访问 */
205203
cur = cur->left;
206204
} else { /* 已经线索化,则访问节点,并删除线索 */
207205
result.push_back(cur->val);
208206
node->right = nullptr;
209-
prev = cur;
210207
cur = cur->right;
211208
}
212209
}

0 commit comments

Comments
 (0)