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:6:1: error: expected unqualified-id before '?' token
    6 | ????int id;
      | ^
a.cc:7:1: error: expected unqualified-id before '?' token
    7 | ????node *left, *right;
      | ^
a.cc:8:1: error: expected unqualified-id before '?' token
    8 | ????node(int id):id(id),left(NULL),right(NULL){}
      | ^
a.cc:12:1: error: expected unqualified-id before '?' token
   12 | ???????map<int,Node*> hashMapping;
      | ^
a.cc:13:1: error: expected unqualified-id before '?' token
   13 | ???????set<int> rootCandidates, nonRootNodes;
      | ^
a.cc:14:1: error: expected unqualified-id before '?' token
   14 | ?
      | ^
a.cc:25:1: error: expected unqualified-id before '?' token
   25 | ???????void preorder(Node* root){
      | ^
a.cc:45:1: error: expected unqualified-id before '?' token
   45 | ???????void inorder(Node* root){
      | ^
a.cc:76:1: error: expected unqualified-id before '?' token
   76 | ???????void postorder(Node* root){
      | ^
a.cc:107:1: error: expected unqualified-id before '?' token
  107 | ?????node* buildTree(){
      | ^
a.cc: In member function 'void Solution::reverse(Node*, Node*)':
a.cc:66:49: error: 'Node' {aka 'struct node'} has no member named 'right'
   66 |             Node *a = NULL,*b = from,*c = from->right;
      |                                                 ^~~~~
a.cc:68:21: error: 'Node' {aka 'struct node'} has no member named 'right'
   68 |                  b->right = a;
      |                     ^~~~~
a.cc:72:30: error: 'Node' {aka 'struct node'} has no member named 'right'
   72 |                     c = c -> right;
      |                              ^~~~~
a.cc: In member function 'void Solution::printPreOrder(node*)':
a.cc:129:1: error: expected primary-expression before '?' token
  129 | ?????????cout<<"Preorder"<<endl;
      | ^
a.cc:129:2: error: expected primary-expression before '?' token
  129 | ?????????cout<<"Preorder"<<endl;
      |  ^
a.cc:129:3: error: expected primary-expression before '?' token
  129 | ?????????cout<<"Preorder"<<endl;
      |   ^
a.cc:129:4: error: expected primary-expression before '?' token
  129 | ?????????cout<<"Preorder"<<endl;
      |    ^
a.cc:129:5: error: expected primary-expression before '?' token
  129 | ?????????cout<<"Preorder"<<endl;
      |     ^
a.cc:129:6: error: expected primary-expression before '?' token
  129 | ?????????cout<<"Preorder"<<endl;
      |      ^
a.cc:129:7: error: expected primary-expression before '?' token
  129 | ?????????cout<<"Preorder"<<endl;
      |       ^
a.cc:129:8: error: expected primary-expression before '?' token
  129 | ?????????cout<<"Preorder"<<endl;
      |        ^
a.cc:129:9: error: expected primary-expression before '?' token
  129 | ?????????cout<<"Preorder"<<endl;
      |         ^
a.cc:129:32: error: expected ':' before ';' token
  129 | ?????????cout<<"Preorder"<<endl;
      |                                ^
a.cc:129:32: error: expected primary-expression before ';' token
a.cc:129:32: error: expected ':' before ';' token
a.cc:129:32: error: expected primary-expression before ';' token
a.cc:129:32: error: expected ':' before ';' token
a.cc:129:32: error: expected primary-expression before ';' token
a.cc:129:32: error: expected ':' before ';' token
a.cc:129:32: error: expected primary-expression before ';' token
a.cc:129:32: error: expected ':' before ';' token
a.cc:129:32: error: expected primary-expression before ';' token
a.cc:129:32: error: expected ':' before ';' token
a.cc:129:32: error: expected primary-expression before ';' token
a.cc:129:32: error: expected ':' before ';' token
a.cc:129:32: error: expected primary-expression before ';' token
a.cc:129:32: error: expected ':' before ';' token
a.cc:129:32: error: expected primary-expression before ';' token
a.cc:129:32: error: expected ':' before ';' token
a.cc:129:32: error: expected primary-expression before ';' token
a.cc:130:1: error: expected primary-expression before '?' token
  130 | ?????????preorder(root);
      | ^
a.cc:130:2: error: expected primary-expression before '?' token
  130 | ?????????preorder(root);
      |  ^
a.cc:130:3: error: expected primary-expression before '?' token
  130 | ?????????preorder(root);
      |   ^
a.cc:130:4: error: expected primary-expression before '?' token
  130 | ?????????preorder(root);
      |    ^
a.cc:130:5: error: expected primary-expression before '?' token
  130 | ?????????preorder(root);
      |     ^
a.cc:130:6: error: expected primary-expression before '?' token
  130 | ?????????preorder(root);
      |      ^
a.cc:130:7: error: expected primary-expression before '?' token
  130 | ?????????preorder(root);
      |       ^
a.cc:130:8: error: expected primary-expression before '?' token
  130 | ?????????preorder(root);
      |        ^
a.cc:130:9: error: expected primary-expression before '?' token
  130 | ?????????preorder(root);
      |         ^
a.cc:130:10: error: 'preorder' was not declared in this scope
  130 | ?????????preorder(root);
      |          ^~~~~~~~
a.cc:130:24: error: expected ':' before ';' token
  130 | ?????????preorder(root);
      |                        ^
a.cc:130:24: error: expected primary-expression before ';' token
a.cc:130:24: error: expected ':' before ';' token
a.cc:130:24: error: expected primary-expression before ';' token
a.cc:130:24: error: expected ':' before ';' token
a.cc:130:24: error: expected primary-expression before ';' token
a.cc:130:24: error: expected ':' before ';' token
a.cc:130:24: error: expected primary-expression before ';' token
a.cc:130:24: error: expected ':' before ';' token
a.cc:130:24: error: expected primary-expression before ';' token
a.cc:130:24: error: expected ':' before ';' token
a.cc:130:24: error: expected primary-expression before ';' token
a.cc:130:24: error: expected ':' before ';' token
a.cc:130:24: error: expected primary-expression before ';' token
a.cc:130:24: error: expected ':' before ';' token
a.cc:130:24: error: expected primary-expression before ';' token
a.cc:130:24: error: expected ':' before ';' token
a.cc:130:24: error: expected primary-expression before ';' token
a.cc:131:1: error: expected primary-expression before '?' token
  131 | ?????????cout<<endl;
      | ^
a.cc:131:2: error: expected primary-expression before '?' token
  131 | ?????????cout<<endl;
      |  ^
a.cc:131:3: error: expected primary-expression before '?' token
  131 | ?????????cout<<endl;
      |   ^
a.cc:131:4: error: expected primary-expression before '?' token
  131 | ?????????cout<<endl;
      |    ^
a.cc:131:5: error: expected primary-expression before '?' token
  131 | ?????????cout<<endl;
      |     ^
a.cc:131:6: error: expected primary-expression before '?' token
  131 | ?????????cout<<endl;
      |      ^
a.cc:131:7: error: expected primary-expression before '?' token
  131 | ?????????cout<<endl;
      |       ^
a.cc:131:8: error: expected primary-expression before '?' token
  131 | ?????????cout<<endl;
      |        ^
a.cc:131:9: error: expected primary-expression before '?' token
  131 | ?????????cout<<endl;
      |         ^
a.cc:131:20: error: expected ':' before ';' token
  131 | ?????????cout<<endl;
      |                    ^
a.cc:131:20: error: expected primary-expression before ';' token
a.cc:131:20: error: expected ':' before ';' token
a.cc:131:20: error: expected primary-expression before ';' token
a.cc:131:20: error: expected ':' before ';' token
a.cc:131:20: error: expected primary-expression before ';' token
a.cc:131:20: error: expected ':' before ';' token
a.cc:131:20: error: expected primary-expression before ';' token
a.cc:131:20: error: expected ':' before ';' token
a.cc:131:20: error: expected primary-expression before ';' token
a.cc:131:20: error: expected ':' before ';' token
a.cc:131:20: error: expected primary-expression before ';' token
a.cc:131:20: error: expected ':' before ';' token
a.cc:131:20: error: expected primary-expression before ';' token
a.cc:131:20: error: expected ':' before ';' token
a.cc:131:20: error: expected primary-expression before ';' token
a.cc:131:20: error: expected ':' before ';' token
a.cc:131:20: error: expected primary-expression before ';' token
a.cc:132:1: error: expected primary-expression before '?' token
  132 | ?????}
      | ^
a.cc:132:2: error: expected primary-expression before '?' token
  132 | ?????}
      |  ^
a.cc:132:3: error: expected primary-expression before '?' token
  132 | ?????}
      |   ^
a.cc:132:4: error: expected primary-expression before '?' token
  132 | ?????}
      |    ^
a.cc:132:5: error: expected primary-expression before '?' token
  132 | ?????}
      |     ^
a.cc:132:6: error: expected primary-expression before '}' token
  132 | ?????}
      |      ^
a.cc:132:6: error: expected ':' before '}' token
a.cc:132:6: error: expected primary-expression before '}' token
a.cc:132:6: error: expected ':' before '}' token
a.cc:132:6: error: expected primary-expression before '}' token
a.cc:132:6: error: expected ':' before '}' token
a.cc:132:6: error: expected primary-expression before '}' token
a.cc:132:6: error: expected ':' before '}' token
a.cc:132:6: error: expected primary-expression before '}' token
a.cc:132:6: error: expected ':' before '}' token
a.cc:132:6: error: expected primary-expression before '}' token
a.cc: In member function 'void Solution::printInOrder(node*)':
a.cc:134:1: error: expected primary-expression before '?' token
  134 | ?????????cout<<"Inorder"<<endl;
      | ^
a.cc:134:2: error: expected primary-expression before '?' token
  134 | ?????????cout<<"Inorder"<<endl;
      |  ^
a.cc:134:3: error: expected primary-expression before '?' token
  134 | ?????????cout<<"Inorder"<<endl;
      |   ^
a.cc:134:4: error: expected primary-expression before '?' token
  134 | ?????????cout<<"Inorder"<<endl;
      |    ^
a.cc:134:5: error: expected primary-expression before '?' token
  134 | ?????????cout<<"Inorder"<<endl;
      |     ^
a.cc:134:6: error: expected primary-expression before '?' token
  134 | ?????????cout<<"Inorder"<<endl;
      |      ^
a.cc:134:7: error: expected primary-expression before '?' token
  134 | ?????????cout<<"Inorder"<<endl;
      |       ^
a.cc:134:8: error: expected primary-expression before '?' token
  134 | ?????????c