A
andrew browning
gbd says the segmentation fault is being generated in the insert
function.
//CONSTRUCTOR
tree():data(value_type()), left(0), right(0){};
tree(value_type vt, tree* l = 0, tree* r = 0):
data(vt), left(l), right(r) {};
//PRIVATE MEMBERS
value_type data;
tree *left;
tree *right;
//INSERT AND ADD NODE FUNCTIONS
tree::tree* tree::newNode(value_type new_data){
tree* node = new tree (data);
node->data = data;
node->left = 0;
node->right= 0;
return node;
}
tree::tree* tree::insert(tree* node, value_type new_data){
if (node == 0){
return(newNode(data));
}else
if(data <= node->data){
node->left = insert(node->left, data);
}else
node->right = insert(node->right, data);
return node;
}
//DRIVER
#include<iostream>
#include "tree.h"
using namespace std;
using namespace abrowning_13;
int main(){
tree t1;
tree* tree_ptr;
int user_input;
while(cin.peek() != EOF){
t1.insert(tree_ptr, user_input);
}
t1.inorder_print(tree_ptr);
return 0;
}
function.
//CONSTRUCTOR
tree():data(value_type()), left(0), right(0){};
tree(value_type vt, tree* l = 0, tree* r = 0):
data(vt), left(l), right(r) {};
//PRIVATE MEMBERS
value_type data;
tree *left;
tree *right;
//INSERT AND ADD NODE FUNCTIONS
tree::tree* tree::newNode(value_type new_data){
tree* node = new tree (data);
node->data = data;
node->left = 0;
node->right= 0;
return node;
}
tree::tree* tree::insert(tree* node, value_type new_data){
if (node == 0){
return(newNode(data));
}else
if(data <= node->data){
node->left = insert(node->left, data);
}else
node->right = insert(node->right, data);
return node;
}
//DRIVER
#include<iostream>
#include "tree.h"
using namespace std;
using namespace abrowning_13;
int main(){
tree t1;
tree* tree_ptr;
int user_input;
while(cin.peek() != EOF){
t1.insert(tree_ptr, user_input);
}
t1.inorder_print(tree_ptr);
return 0;
}