From 161ff7d792115a8bc1f71229382a2f654ad00ba2 Mon Sep 17 00:00:00 2001 From: sheroz Date: Sat, 30 Sep 2023 17:50:19 +0300 Subject: [PATCH] refactored --- README.md | 8 +++++++- src/binary_tree.rs | 8 ++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 8e116e7..91d72e3 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,15 @@ Tree and parent-child relationship samples for learning purposes -- [Generic Tree](src/generic_tree.rs) - [Binary Tree](src/binary_tree.rs) + - Traversal + - In-order + - Inverting + - Recursive + - Iterative - [Binary Search Tree](src/binary_search_tree.rs) + - Search +- [Generic Tree](src/generic_tree.rs) ## Useful insights diff --git a/src/binary_tree.rs b/src/binary_tree.rs index 86b4ce5..9212afa 100644 --- a/src/binary_tree.rs +++ b/src/binary_tree.rs @@ -202,8 +202,8 @@ impl BinaryTree { } // swap child nodes - let tmp = node.right.clone(); - node.right = node.left.clone(); + let tmp = node.right.take(); + node.right = node.left.take(); node.left = tmp; } @@ -220,8 +220,8 @@ impl BinaryTree { } // swap child nodes - let tmp = node.right.clone(); - node.right = node.left.clone(); + let tmp = node.right.take(); + node.right = node.left.take(); node.left = tmp; } }