Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C > Binary Tree 2 L...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 8 Topic 24598 of 27670
Post > Topic >>

Binary Tree 2 Linked List

by DanielJohnson <diffuser78@[EMAIL PROTECTED] > Feb 16, 2008 at 10:13 AM

I am not asking any solution but please tell me why g++ compiler gives
me the following error. I am using g++ as against gcc only because I
used #include<stack> from C++ STL to store the values in stack as
opposed to creating one of mine. All of my code is in C.

I am converting a Binary Tree to a Doubly Linked List by using an
inorder traversal and changing pointers.

btree struct looks like this

typedef struct btree{
        struct btree* left;
        int data;
        struct btree* right;

} btree;

And this is my function, where I get the error from g++ compiler

btree* ConvertBinaryTree2LinkedList(btree* root){
        btree *cursor = root;
        btree *head = NULL; // return as first element of linked list
        int isLeftMost = 1;
        stack < btree* > S;
        int done = 0;

        // Iterative Inorder Traversal
        while(!done){
                if (cursor != NULL) {
                        S.push(cursor);
                        cursor=cursor->left;
                        if (isLeftMost) head = cursor;
                }
                else{
                        if(!S.empty()){
                                isLeftMost = 0;
                                cursor = S.top();
                                S.pop();
                                cursor->right = S.top();
                                S.top()->left = cursor;
                                cursor = cursor->right;
                        }
                        else{
                                done = 1;
                        }
                }
        }
        return head;

}

BinaryTree2LinkedList.cpp: In function 'btree*
ConvertBinaryTree2LinkedList(btree*)':
BinaryTree2LinkedList.cpp:72: error: 'stack' was not declared in this
scope
BinaryTree2LinkedList.cpp:72: error: expected primary-expression
before '*' token
BinaryTree2LinkedList.cpp:72: error: expected primary-expression
before '>' token
BinaryTree2LinkedList.cpp:72: error: 'S' was not declared in this
scope

Please help to fix the error. Every help is appreciated.
 




 8 Posts in Topic:
Binary Tree 2 Linked List
DanielJohnson <diffuse  2008-02-16 10:13:53 
Re: Binary Tree 2 Linked List
Richard Heathfield <rj  2008-02-16 18:26:18 
Re: Binary Tree 2 Linked List
DanielJohnson <diffuse  2008-02-16 10:25:48 
Re: Binary Tree 2 Linked List
Richard Heathfield <rj  2008-02-16 18:31:52 
Re: Binary Tree 2 Linked List
DanielJohnson <diffuse  2008-02-16 10:31:23 
Re: Binary Tree 2 Linked List
Richard Heathfield <rj  2008-02-16 18:40:25 
Re: Binary Tree 2 Linked List
DanielJohnson <diffuse  2008-02-16 10:54:51 
Re: Binary Tree 2 Linked List
CBFalconer <cbfalconer  2008-02-16 20:15:18 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Oct 10 22:08:51 CDT 2008.