Search
 
SCRIPT & CODE EXAMPLE
 

CPP

c++ print binary treenode

void printBT(const std::string& prefix, const BSTNode* node, bool isLeft)
{
    if( node != nullptr )
    {
        std::cout << prefix;

        std::cout << (isLeft ? "├──" : "└──" );

        // print the value of the node
        std::cout << node->m_val << std::endl;

        // enter the next tree level - left and right branch
        printBT( prefix + (isLeft ? "│   " : "    "), node->m_left, true);
        printBT( prefix + (isLeft ? "│   " : "    "), node->m_right, false);
    }
}

void printBT(const BSTNode* node)
{
    printBT("", node, false);    
}

// pass the root node of your binary tree
printBT(root);
Comment

PREVIOUS NEXT
Code Example
Cpp :: sqrt in c++ 
Cpp :: what is thread in c++ 
Cpp :: opencv open image c++ 
Cpp :: c++ initialize vector of vector with size 
Cpp :: c++ rand include 
Cpp :: c++ casting 
Cpp :: How to create files in C++ 
Cpp :: how to empty an array c++ 
Cpp :: how to print a text in c++ 
Cpp :: print duplicate characters from string in c++ 
Cpp :: unreal engine c++ 
Cpp :: priority queue smallest first 
Cpp :: cpp func as const 
Cpp :: substr in cpp 
Cpp :: how to compare two char* in c++ 
Cpp :: C++, for-loop over an array array 
Cpp :: creare array con c++ 
Cpp :: C++ std::optional 
Cpp :: reversing a string in c++ 
Cpp :: print stack without pop c++ 
Cpp :: c++ for loop multiple variables 
Cpp :: how to use command line arguments with integers in c++ 
Cpp :: explicit c++ 
Cpp :: prime or not in cpp 
Cpp :: c++ inheritance constructor 
Cpp :: cyclic array rotation in cpp 
Cpp :: text color c++ 
Cpp :: print reverse number 
Cpp :: converting char to integer c++ 
Cpp :: Reverse a linked list geeksforgeeks in c++ 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =