online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
#include <iostream> using namespace std; class node{ public: int data; node* left; node* right; node(int val){ data = val; left = NULL; right = NULL; } }; node* createTreeFromTraversal(int* inorder, int* preorder, int start, int end){ static int i = 0; //static makes sure that the variable stores the value from the //prev function call if (start > end){ return NULL; } node* root = new node(preorder[i]); int index = -1; for(int j = start; j <= end; j++){ if (inorder[j] == preorder[i]){ index = j; break; } } i++; root->left = createTreeFromTraversal(inorder, preorder, start, index - 1); root->right = createTreeFromTraversal(inorder, preorder, index + 1, end); return root; } void print(node* root){ if (root == NULL){ return; } node* left = root->left; node* right = root->right; if (left == NULL){ cout << "END => "; } else { cout << left->data << " => "; } cout << root->data; if (right == NULL){ cout << " <= END"; } else { cout << right->data << " <= "; } cout << endl; print(root->left); print(root->right); } int main(){ // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif int n, m; cin >> n; int preorder[n], inorder[n]; for(int i = 0; i < n; i++){ cin >> preorder[i]; } cin >> m; for(int i = 0; i < m; i++){ cin >> inorder[i]; } node* root = createTreeFromTraversal(inorder, preorder, 0, n - 1, m - 1); print(root); cout << endl; }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue