indentation

This commit is contained in:
Jidong Xiao
2025-03-27 23:25:19 -04:00
committed by JamesFlare
parent eb0d7868dc
commit f634f39d05
3 changed files with 42 additions and 42 deletions

View File

@@ -10,26 +10,26 @@ public:
};
void inorderTraversal(TreeNode* root) {
TreeNode *current=root;
TreeNode *rightmost;
while(current!=NULL){
if(current->left!=NULL){
rightmost=current->left;
while(rightmost->right!=NULL && rightmost->right!=current){
rightmost=rightmost->right;
}
if(rightmost->right==NULL){ /* first time */
rightmost->right=current;
current=current->left;
}else{ /* second time */
std::cout << current->val << " ";
rightmost->right=NULL;
current=current->right;
}
}else{ /* nodes which do not have left child */
TreeNode *current=root;
TreeNode *rightmost;
while(current!=NULL){
if(current->left!=NULL){
rightmost=current->left;
while(rightmost->right!=NULL && rightmost->right!=current){
rightmost=rightmost->right;
}
if(rightmost->right==NULL){ /* first time */
rightmost->right=current;
current=current->left;
}else{ /* second time */
std::cout << current->val << " ";
rightmost->right=NULL;
current=current->right;
}
}else{ /* nodes which do not have left child */
std::cout << current->val << " ";
current=current->right;
}
}
return;
}