D
DanielJohnson
I am not asking any solution but please tell me why g++ compiler gives
me the following error. 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
bool isLeftMost = true;
stack < btree* > S;
bool done = false;
// Iterative Inorder Traversal
while(!done){
if (cursor != NULL) {
S.push(cursor);
cursor=cursor->left;
if (isLeftMost) head = cursor;
}
else{
if(!S.empty()){
isLeftMost = false;
cursor = S.top();
S.pop();
cursor->right = S.top();
S.top()->left = cursor;
cursor = cursor->right;
}
else{
done = true;
}
}
}
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.
me the following error. 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
bool isLeftMost = true;
stack < btree* > S;
bool done = false;
// Iterative Inorder Traversal
while(!done){
if (cursor != NULL) {
S.push(cursor);
cursor=cursor->left;
if (isLeftMost) head = cursor;
}
else{
if(!S.empty()){
isLeftMost = false;
cursor = S.top();
S.pop();
cursor->right = S.top();
S.top()->left = cursor;
cursor = cursor->right;
}
else{
done = true;
}
}
}
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.