Example #1
0
int main()
{
    vector<int> inorder;
    inorder.push_back(4);
    inorder.push_back(2);
    inorder.push_back(6);
    inorder.push_back(5);
    inorder.push_back(1);
    inorder.push_back(3);
    inorder.push_back(10);
    inorder.push_back(8);
    inorder.push_back(7);
    inorder.push_back(9);
        vector<int> postorder;
    postorder.push_back(4);
    postorder.push_back(6);
    postorder.push_back(5);
    postorder.push_back(2);
    postorder.push_back(10);
    postorder.push_back(8);
    postorder.push_back(9);
    postorder.push_back(7);
    postorder.push_back(3);
    postorder.push_back(1);

    Solution s;
    TreeNode *tree=s.buildTree(inorder,postorder);
    cout<<"____________________"<<endl;
    output(tree);
    return 0;
}
int main()
{
	vector<int> inorder;
	inorder.push_back(-1);
	Solution sol;
	sol.buildTree(inorder,inorder);return 0;
};
Example #3
0
int main()
{
    Solution s;
    std::vector<int> preorder{1,2,4,5,3,6};
    std::vector<int> inorder{4,2,5,1,3,6};
    print_bfs(s.buildTree(preorder, inorder));
}
Example #4
0
int main(int argc, char const *argv[])
{
    vector<int> a, b;
    a.push_back(1);
    a.push_back(2);
    b.push_back(2);
    b.push_back(1);
/*  a.push_back(1);
    a.push_back(3);
    a.push_back(2);
    a.push_back(4);
    a.push_back(6);
    a.push_back(5);
    b.push_back(1);
    b.push_back(2);
    b.push_back(3);
    b.push_back(4);
    b.push_back(5);
    b.push_back(6);*/
    Solution s;
    TreeNode* p = s.buildTree(a, b);
    // while (p != NULL) {
    //  cout << p->val;
    //  p = p->left;
    // }
    //for (int i = 0; i < 3; ++i)
    //{
   //   cout << A[i];
    //}
    //cout << A[0]  << A[1] << A[2] << endl;
    return 0;
}
int main(void) {
	Solution* s = new Solution();
	vector<int> preorder;
	preorder.push_back(1);
	preorder.push_back(2);
	preorder.push_back(4);
	preorder.push_back(5);
	preorder.push_back(3);
	preorder.push_back(6);
	vector<int> inorder;
	inorder.push_back(4);
	inorder.push_back(2);
	inorder.push_back(5);
	inorder.push_back(1);
	inorder.push_back(3);
	inorder.push_back(6);
	
	cout << "Solution 1: " << endl;
	TreeNode* root = s->buildTree(preorder, inorder);
	cout << "Flatten finished!" << endl;
	s->outputResult(root);
	
	s->deleteTree(root);
	cout << "Delete tree finished!" << endl;
	
	delete s;
	return 0;
}
Example #6
0
int main()
{
    vector<int> inorder = {1, 2}, postorder = {1, 2};
    Solution solution;
    solution.buildTree(inorder, postorder);
    return 0;
}
int main()
{
    vector<int> v(1, 1);
    v.push_back(2);
    Solution s;
    s.buildTree(v, v);
}
int main()
{
    Solution s;
    vector<int> inorder;
    vector<int> postorder;
    inorder.push_back(4);
    inorder.push_back(2);
    inorder.push_back(5);
    inorder.push_back(1);
    inorder.push_back(6);
    inorder.push_back(3);
    inorder.push_back(7);

    postorder.push_back(4);
    postorder.push_back(5);
    postorder.push_back(2);
    postorder.push_back(6);
    postorder.push_back(7);
    postorder.push_back(3);
    postorder.push_back(1);

    s.buildTree(inorder, postorder);
    cout << endl;
   
    return 0;
}
static void checkConstruct(const std::string &ts)
{
    vector<int> inorder, postorder;
    
    std::stringstream is(ts);
    std::stringstream os;
    BTreeBase<int> tree;

    //construct tree from string
    is >> tree;

    //get traval path
    traval_tree(tree.root(), inorder, true);
    traval_tree(tree.root(), postorder, false);

    //construct tree by inorder and postorder path
    Solution sol;
    BTreeBase<int> ctree(
            sol.buildTree(inorder, postorder));

    //convert tree to string
    os << ctree;

    //check result
    std::string ss = os.str();
    EXPECT_EQ(ts, ss);
}
int main()
{
	Solution solution;
	TreeNode *resultroot;
	vector<int> result;
	
	/*//Testcase1:
	int myints[] = {8,10,11,9,4,5,2,6,7,3,1};
	int myints2[] = { 8,4,10,9,11,2,5,1,6,3,7};*/

	int myints[] = {1,2,3,4};
	int myints2[] = {3,4,2,1};

	//vector<int> preorder=(myints, myints + sizeof(myints) / sizeof(int));
	//vector<int> inorder=(myints2, myints2 + sizeof(myints2) / sizeof(int));
	vector<int> postorder;
	vector<int> inorder;

	inorder.insert(inorder.end(), &myints[0], &myints[sizeof(myints) / sizeof(int)]);
	postorder.insert(postorder.end(), &myints2[0], &myints2[sizeof(myints2) / sizeof(int)]);
	
	resultroot=solution.buildTree(inorder,postorder);
	
	result=solution.postorderTraversal(resultroot);
	for(vector<int>::iterator it2=result.begin();it2!=result.end();it2++)
	{
		cout<<*it2<<",";
	}
    cout<<endl;



	return 0;
}
int main() {
  vector<int> preorder;
  preorder.push_back(1);
  preorder.push_back(2);
  preorder.push_back(4);
  preorder.push_back(5);
  preorder.push_back(3);
  preorder.push_back(6);
  preorder.push_back(7);
  vector<int> inorder;
  inorder.push_back(4);
  inorder.push_back(2);
  inorder.push_back(5);
  inorder.push_back(1);
  inorder.push_back(6);
  inorder.push_back(3);
  inorder.push_back(7);

  Solution sol;
  TreeNode *tree = sol.buildTree(preorder, inorder);

  output(tree);
  destroy_tree(tree);
  return 0;
}
int main() {
	vector<int> in{1, 3, 6};
	vector<int> post{6, 3, 1};

	Solution sol;
	TreeNode* root = sol.buildTree(in, post);
	print_tree(root);
}
int main(int argc, char *argv[]) {
    Solution *s = new Solution;
    vector<int> v1;
    v1.push_back();
    vector<int> v2;
    v2.push_back(-1);
    s->buildTree(v1, v2);
}
Example #14
0
int main(){
    Solution s;
    vector<int> preorder{1,2,4,6,7,3,5}, inorder{2,6,4,7,1,5,3};
    //vector<int> preorder{1,2,3}, inorder{3,2,1};
    TreeNode* t = s.buildTree(preorder, inorder);
    print_postorder(t);
    cout << endl;
    return 0;
}
Example #15
0
int main() {
	int preorder[] = {1, 2};
	int inorder[] = {2, 1};
	vector<int> pre(preorder, preorder + 2);
	vector<int> in(inorder, inorder + 2);
	Solution sol;
	TreeNode *root = sol.buildTree(pre, in);
	return 0;
}
int main(int argc, char* argv[])
{
    vector<int> preOrder = {1, 2, 4, 5, 3, 6, 7};
    vector<int> inOrder = {4, 2, 5, 1, 6, 3, 7};
    //test_vector(preOrder);
    Solution sln;
    TreeNode* root = sln.buildTree(preOrder, inOrder);
    return 0;
}
Example #17
0
int main()
{
    int pre[] = {1, 2, 4, 5, 3, 6};
    int in[] = {4, 2, 5, 1, 3, 6};
    Solution s;
    Node *root = s.buildTree(pre, in, 6);
    s.postorder(root);
    cout << endl;
}
int main(void) {
	Solution solution;
	vector<int> inorder = {2, 1};
	vector<int> postorder = {2, 1};
	TreeNode *root = solution.buildTree(inorder, postorder);
	inorderTraversal(root);
	cout << "\nPassed\n";
	cout << "\nPassed All\n";
	return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
	int inorder_array[] = {8, 4, 9, 2, 10, 5, 11, 1, 12, 6, 13, 3, 14, 7, 15};
	int postorder_array[] = {8, 9, 4, 10, 11, 5, 2, 12, 13, 6, 14, 15, 7, 3, 1};
	vector<int> inorder(inorder_array, inorder_array + 15);
	vector<int> postorder(postorder_array, postorder_array + 15);
	Solution so;
	TreeNode *pRoot = so.buildTree(inorder, postorder);
	return 0;
}
int main()
{
	Solution s;
	int in[]={1,2,3,4};
	int post[]={2,3,1,4};

	vector<int> inVec(in,in+sizeof(in)/sizeof(in[0]));
	vector<int > outvec(post,post+sizeof(post)/sizeof(post[0]));
	TreeNode* tree = s.buildTree(inVec,outvec);
}
int LEET_CONSTRUCT_BINARY_TREE_FROM_INORDER_AND_POSTORDER_TRAVERSAL()
{
    Solution solution;
    int inorderArray[3] = { 1, 2, 3 };
    int postorderArray[3] = { 1, 3, 2 };
    vector<int> inorder(inorderArray, inorderArray + 3);
    vector<int> postorder(postorderArray, postorderArray + 3);
    TreeNode* result = solution.buildTree(inorder, postorder);
    return 0;
}
Example #22
0
int main(int argc, const char *argv[])
{
   Solution sol;
   int in[] = {1, 2, 3, 4};
   vector<int> inorder(in, in+sizeof(in)/sizeof(int));
   int post[] = {3, 2, 4, 1};
   vector<int> postorder(post, post+sizeof(post)/sizeof(int));
   cout << sol.buildTree(inorder, postorder) << endl;
   return 0;
}
int main(){
	int a[] = {1,2,3,4};
	int b[] = {4,3,2,1};
	vector<int> in(a,a+4);
	vector<int> post(b,b+4);
	Solution s;
	TreeNode* tree;
	tree = s.buildTree(in,post);
	PreOrderTraverse(tree);
	return 0;
}
Example #24
0
int main()
{
    int preArr[] = {1, 2, 3};
    int inArr[] = {2, 1, 3};
    vector<int> preVec(preArr, preArr + sizeof(preArr) / sizeof(int));
    vector<int> inVec(inArr, inArr + sizeof(inArr) / sizeof(int));
    Solution s;
    s.buildTree(preVec, inVec);

    return 0;
}
Example #25
0
int main()
{
    pair<vector<int>, vector<int>> testCases[] = { { { 2, 1, 3 }, { 2, 3, 1 } },
                                                   { { 2, 1 }, { 2, 1 } } };
    Solution s;

    for (auto testCase : testCases)
    {
        s.buildTree(testCase.first, testCase.second);
    }
}
Example #26
0
File: main.cpp Project: CCJY/coliru
int main()
{
   vector<int> inp   = { 3, 2, 4, 1, 5, 6 };
   vector<int> postp = { 3, 4, 2, 6, 5, 1 };

   Solution sol;
   TreeNode *ret = sol.buildTree(inp, postp);
   cout << "finished buildTree" << endl;
   //sol.inorderTraverse(ret);
   cout << endl;
   return 0;
}
Example #27
0
int main() {
  vector<int>in;
  vector<int>po;
  in.push_back(1);
  in.push_back(3);
  in.push_back(2);
  po.push_back(3);
  po.push_back(2);
  po.push_back(1);
  Solution s;
  s.buildTree(in,po);
}
Example #28
0
int main()
{
	vector<int> inorder, postorder;
	inorder.push_back(1);
	inorder.push_back(3);
	inorder.push_back(2);
	postorder.push_back(3);
	postorder.push_back(2);
	postorder.push_back(1);
	Solution sl;
	sl.buildTree(inorder, postorder);
}
void main()
{
	Solution sl;
	vector<int> m1;
	m1.push_back(1);
	//m1.push_back(2);
	//m1.push_back(2);
	vector<int> m2;
	m2.push_back(2);
	//m2.push_back(1);
	TreeNode * res=sl.buildTree(m1,m2);
	waitKey();
}
int main() {
  Solution sol;

  int post_order[] = {9, 7, 3, 5, 6, 4, 2};
  int in_order[] = {9, 3, 7, 2, 5, 4, 6};
  vector<int> postorder(post_order,
                        post_order+sizeof(post_order)/sizeof(post_order[0]));
  vector<int> inorder(in_order,
                      in_order+sizeof(in_order)/sizeof(in_order[0]));

  sol.t = sol.buildTree(inorder, postorder);
  return 0;
}