Language: C++

#
include < iostream > #include < map > #include < set >
    using namespace std;
typedef struct node {????
    int id;????
    node * left, * right;????
    node(int id): id(id), left(NULL), right(NULL) {}
}
Node;
class Solution {
    private: ???????map < int, Node * > hashMapping;???????
    set < int > rootCandidates, nonRootNodes;????????
    Node * createNode(int ID) {??????????????
        if (ID != -1) {???????????????
            if (hashMapping.find(ID) == hashMapping.end()) {????????????????????
                hashMapping[ID] = new Node(ID);??????????????
            }??????????????
            return hashMapping[ID];???????????
        } else {??????????????
            return NULL;???????????
        }???????
    }???????
    void preorder(Node * root) {?????????
        while (root) {??????????????
            while (root - > left && root - > right) {???????????????????????????????
                Node * currNode = root - > left;????????????????
                while (currNode - > right != NULL && ?????????????????????
                       currNode - > right != root) {??????????????????????
                    currNode = currNode - > right;????????????????
                }???????????????????????????????
                if (currNode - > right == NULL) {???????????????????
                    currNode - > right = root;???????????????????
                    break;????????????????
                } else {???????????????????
                    currNode - > right = NULL;???????????????????
                    root = root - > right;??????????????????????????????????
                }???????????????????????
            }?????????????
            cout << " " << root - > id;?????????????????????????????????????????????????
            root = root - > left ? root - > left : root - > right;???????????
        }????????
    }???????
    void inorder(Node * root) {???????????
        while (root) {??????????????
            while (root - > left) {???????????????????????????????
                Node * currNode = root - > left;????????????????
                while (currNode - > right != NULL && ??????????????????????
                       currNode - > right != root) {??????????????????????
                    currNode = currNode - > right;????????????????
                }???????????????????????????????
                if (currNode - > right == NULL) {???????????????????
                    currNode - > right = root;???????????????????
                    root = root - > left;????????????????
                } else {???????????????????
                    currNode - > right = NULL;???????????????????
                    break;????????????????
                }???????????????????????
            }?????????????
            cout << " " << root - > id;????????????????????????????????????
            root = root - > right;???????????
        }????????
    }
    void reverse(Node * from, Node * to) {
        Node * a = NULL, * b = from, * c = from - > right;
        while (a != to) {
            b - > right = a;
            a = b;
            b = c;
            if (c) {
                c = c - > right;
            }
        }
    }???????
    void postorder(Node * root) {??????????
        Node * forgeRoot = new Node(-1);
        forgeRoot - > left = root;
        root = forgeRoot;
        do {??????????????
            while (root - > left) {???????????????????????????????
                Node * currNode = root - > left;????????????????
                while (currNode - > right != NULL && ?????????????????????
                       currNode - > right != root) {??????????????????????
                    currNode = currNode - > right;????????????????
                }???????????????????????????????
                if (currNode - > right == NULL) {???????????????????
                    currNode - > right = root;???????????????????
                    root = root - > left;????????????????
                } else {???????????????????
                    currNode - > right = NULL;???????????????????
                    root = root - > right;????????????????
                }???????????????????????
            }
            Node * from = root - > right - > left, * to = root;
            reverse(from, to);
            while (from != to) {
                cout << " " << from - > id;
                from = from - > right;
            }
            cout << " " << from - > id;
            reverse(from, to);?????????????
            root = root - > right;???????????
        } while (root != forgeRoot);?????
    }
    public: ????
      node * buildTree() {???????????
        hashMapping.clear();???????????
        rootCandidates.clear();???????????
        nonRootNodes.clear();???????????
        int num, rootID = -1;???????????
        cin >> num;???????????
        while (num--) {?????????????????
            int ID, leftID, rightID;?????????????????
            cin >> ID >> leftID >> rightID;?????????????????
            if (nonRootNodes.find(ID) == nonRootNodes.end()) {????????????????????
                rootCandidates.insert(ID);?????????????????
            }?????????????????
            nonRootNodes.insert(leftID);?????????????????
            rootCandidates.erase(leftID);?????????????????
            nonRootNodes.insert(rightID);?????????????????
            rootCandidates.erase(rightID);?????????????????
            createNode(ID) - > left = createNode(leftID);?????????????????
            createNode(ID) - > right = createNode(rightID);???????????
        }???????????
        return hashMapping[ * rootCandidates.begin()];?????
    }
    void printPreOrder(node * root) {?????????
        cout << "Preorder" << endl;?????????
        preorder(root);?????????
        cout << endl;?????
    }
    void printInOrder(node * root) {?????????
        cout << "Inorder" << endl;?????????
        inorder(root);?????????
        cout << endl;?????
    }
    void printPostOrder(node * root) {?????????
        cout << "Postorder" << endl;?????????
        postorder(root);?????????
        cout << endl;????
    }
}
sln;
int main(int argc, char * argv[]) {????
    ios::sync_with_stdio(false);????
    node * root = sln.buildTree();????
    sln.printPreOrder(root);????
    sln.printInOrder(root);????
    sln.printPostOrder(root);????
    return 0;
}

Compiler output:
a.cc:2:22: error: stray '#' in program
    2 | include < iostream > #include < map > #include < set >
      |                      ^
a.cc:2:39: error: stray '#' in program
    2 | include < iostream > #include < map > #include < set >
      |                                       ^
a.cc:2:1: error: 'include' does not name a type
    2 | include < iostream > #include < map > #include < set >
      | ^~~~~~~
a.cc:4:22: error: expected unqualified-id before '?' token
    4 | typedef struct node {????
      |                      ^
a.cc:5:12: error: expected unqualified-id before '?' token
    5 |     int id;????
      |            ^
a.cc:6:26: error: expected unqualified-id before '?' token
    6 |     node * left, * right;????
      |                          ^
a.cc:11:14: error: expected unqualified-id before '?' token
   11 |     private: ???????map < int, Node * > hashMapping;???????
      |              ^
a.cc:11:53: error: expected unqualified-id before '?' token
   11 |     private: ???????map < int, Node * > hashMapping;???????
      |                                                     ^
a.cc:12:46: error: expected unqualified-id before '?' token
   12 |     set < int > rootCandidates, nonRootNodes;????????
      |                                              ^
a.cc:22:6: error: expected unqualified-id before '?' token
   22 |     }???????
      |      ^
a.cc:42:6: error: expected unqualified-id before '?' token
   42 |     }???????
      |      ^
a.cc:73:6: error: expected unqualified-id before '?' token
   73 |     }???????
      |      ^
a.cc:104:13: error: expected unqualified-id before '?' token
  104 |     public: ????
      |             ^
a.cc: In member function 'void Solution::reverse(Node*, Node*)':
a.cc:64:20: error: 'NULL' was not declared in this scope
   64 |         Node * a = NULL, * b = from, * c = from - > right;
      |                    ^~~~
a.cc:1:1: note: 'NULL' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'
  +++ |+#include <cstddef>
    1 | #
a.cc:66:13: error: 'b' was not declared in this scope
   66 |             b - > right = a;
      |             ^
a.cc:66:17: error: expected primary-expression before '>' token
   66 |             b - > right = a;
      |                 ^
a.cc:66:19: error: 'right' was not declared in this scope
   66 |             b - > right = a;
      |                   ^~~~~
a.cc:68:17: error: 'c' was not declared in this scope
   68 |             b = c;
      |                 ^
a.cc:70:25: error: expected primary-expression before '>' token
   70 |                 c = c - > right;
      |                         ^
a.cc: In member function 'void Solution::printPreOrder(node*)':
a.cc:126:38: error: expected primary-expression before '?' token
  126 |     void printPreOrder(node * root) {?????????
      |                                      ^
a.cc:126:39: error: expected primary-expression before '?' token
  126 |     void printPreOrder(node * root) {?????????
      |                                       ^
a.cc:126:40: error: expected primary-expression before '?' token
  126 |     void printPreOrder(node * root) {?????????
      |                                        ^
a.cc:126:41: error: expected primary-expression before '?' token
  126 |     void printPreOrder(node * root) {?????????
      |                                         ^
a.cc:126:42: error: expected primary-expression before '?' token
  126 |     void printPreOrder(node * root) {?????????
      |                                          ^
a.cc:126:43: error: expected primary-expression before '?' token
  126 |     void printPreOrder(node * root) {?????????
      |                                           ^
a.cc:126:44: error: expected primary-expression before '?' token
  126 |     void printPreOrder(node * root) {?????????
      |                                            ^
a.cc:126:45: error: expected primary-expression before '?' token
  126 |     void printPreOrder(node * root) {?????????
      |                                             ^
a.cc:126:46: error: expected primary-expression before '?' token
  126 |     void printPreOrder(node * root) {?????????
      |                                              ^
a.cc:127:9: error: 'cout' was not declared in this scope
  127 |         cout << "Preorder" << endl;?????????
      |         ^~~~
a.cc:127:31: error: 'endl' was not declared in this scope
  127 |         cout << "Preorder" << endl;?????????
      |                               ^~~~
a.cc:127:35: error: expected ':' before ';' token
  127 |         cout << "Preorder" << endl;?????????
      |                                   ^
a.cc:127:35: error: expected primary-expression before ';' token
a.cc:127:35: error: expected ':' before ';' token
a.cc:127:35: error: expected primary-expression before ';' token
a.cc:127:35: error: expected ':' before ';' token
a.cc:127:35: error: expected primary-expression before ';' token
a.cc:127:35: error: expected ':' before ';' token
a.cc:127:35: error: expected primary-expression before ';' token
a.cc:127:35: error: expected ':' before ';' token
a.cc:127:35: error: expected primary-expression before ';' token
a.cc:127:35: error: expected ':' before ';' token
a.cc:127:35: error: expected primary-expression before ';' token
a.cc:127:35: error: expected ':' before ';' token
a.cc:127:35: error: expected primary-expression before ';' token
a.cc:127:35: error: expected ':' before ';' token
a.cc:127:35: error: expected primary-expression before ';' token
a.cc:127:35: error: expected ':' before ';' token
a.cc:127:35: error: expected primary-expression before ';' token
a.cc:127:36: error: expected primary-expression before '?' token
  127 |         cout << "Preorder" << endl;?????????
      |                                    ^
a.cc:127:37: error: expected primary-expression before '?' token
  127 |         cout << "Preorder" << endl;?????????
      |                                     ^
a.cc:127:38: error: expected primary-expression before '?' token
  127 |         cout << "Preorder" << endl;?????????
      |                                      ^
a.cc:127:39: error: expected primary-expression before '?' token
  127 |         cout << "Preorder" << endl;?????????
      |                                       ^
a.cc:127:40: error: expected primary-expression before '?' token
  127 |         cout << "Preorder" << endl;?????????
      |                                        ^
a.cc:127:41: error: expected primary-expression before '?' token
  127 |         cout << "Preorder" << endl;?????????
      |                                         ^
a.cc:127:42: error: expected primary-expression before '?' token
  127 |         cout << "Preorder" << endl;?????????
      |                                          ^
a.cc:127:43: error: expected primary-expression before '?' token
  127 |         cout << "Preorder" << endl;?????????
      |                                           ^
a.cc:127:44: error: expected primary-expression before '?' token
  127 |         cout << "Preorder" << endl;?????????
      |                                            ^
a.cc:128:9: error: 'preorder' was not declared in this scope
  128 |         preorder(root);?????????
      |         ^~~~~~~~
a.cc:128:23: error: expected ':' before ';' token
  128 |         preorder(root);?????????
      |                       ^
a.cc:128:23: error: expected primary-expression before ';' token
a.cc:128:23: error: expected ':' before ';' token
a.cc:128:23: error: expected primary-expression before ';' token
a.cc:128:23: error: expected ':' before ';' token
a.cc:128:23: error: expected primary-expression before ';' token
a.cc:128:23: error: expected ':' before ';' token
a.cc:128:23: error: expected primary-expression before ';' token
a.cc:128:23: error: expected ':' before ';' token
a.cc:128:23: error: expected primary-expression before ';' token
a.cc:128:23: error: expected ':' before ';' token
a.cc:128:23: error: expected primary-expression before ';' token
a.cc:128:23: error: expected ':' before ';' token
a.cc:128:23: error: expected primary-expression before ';' token
a.cc:128:23: error: expected ':' before ';' token
a.cc:128:23: error: expected primary-expression before ';' token
a.cc:128:23: error: expected ':' before ';' token
a.cc:128:23: error: expected primary-expression before ';' token
a.cc:128:24: error: expected primary-expression before '?' token
  128 |         preorder(root);?????????
      |                        ^
a.cc:128:25: error: expected primary-expression before '?' token
  128 |         preorder(root);?????????
      |                         ^
a.cc:128:26: error: expected primary-expression before '?' token
  128 |         preorder(root);?????????
      |                          ^
a.cc:128:27: error: expected primary-expression before '?' token
  128 |         preorder(root);?????????
      |                           ^
a.cc:128:28: error: expected primary-expression before '?' token
  128 |         preorder(root);?????????
      |                            ^
a.cc:128:29: error: expected primary-expression before '?' token
  128 |         preorder(root);?????????
      |                             ^
a.cc:128:30: error: expected primary-expression before '?' token
  128 |         preorder(root);?????????
      |                              ^
a.cc:128:31: error: expected primary-expression before '?' token
  128 |         preorder(root);?????????
      |                               ^
a.cc:128:32: error: expected primary-expression before '?' token
  128 |         preorder(root);?????????
      |                                ^
a.cc:129:21: error: expected ':' before ';' token
  129 |         cout << endl;?????
      |                     ^
a.cc:129:21: error: expected primary-expression before ';' token
a.cc:129:21: error: expected ':' before ';' token
a.cc:129:21: error: expected primary-expression before ';' token
a.cc:129:21: error: expected ':' before ';' token
a.cc:129:21: error: expected primary-expression before ';' token
a.cc:129:21: error: expected ':' before ';' token
a.cc:129:21: error: expected primary-expression before ';' token
a.cc:1