/cg

Primary LanguageC++

Competitive coding practice repo

Tree:

Supplementary files:

  1. gen_tree.cpp

    UDTs:

    • Node

      Stores the integer value of node of the tree and the points to its left and right branches.

      struct Node {
          int data;
          Node *left, *right;
      };
      

    Functions:

    • Node *BuildTree(string seq);

      Generate a tree from a string with node values separatedby space and N as null node, the values are to be takenin level order.

      example:

      input tree:
                                    1
                                  /  \  
                                 2    3 
                                / \    \
                               4   6    7
                                  /    / \
                                 5    8   9
      
      input: 1 2 3 4 6 N 7 N N 5 N 8 9
      output: <pointer to the root node>