Skip to main content
gamedev.net
🔒 Locked

problem with BST

Started by johnkull Mar 11, 2003 at 6:30 PM 3 replies 550+ views
Original Post
johnkull
johnkull
When I try to insert a node into the tree I recieve an unhandled exception error and I can''t find out why? Any Help please void insertBST(node *&root, node *temp) { if(root == NULL) root = temp; else { node *parent(root); while((temp->data<=parent->data && parent->left!= NULL) || (temp->data >= parent->data && parent->right != NULL)) { if(temp->data <= parent->data) parent = parent->left; else parent = parent->right; } if(temp->data <= parent->data) parent->left=temp; else parent->right = temp; } }
Beer Hunter
Beer Hunter
C++ already has a binary tree (set) - it probably does everything you want from a binary tree.
Zipster
Zipster
quote:
Original post by Anonymous Poster
I think "binary search trees" are different than "binary trees".


You better believe it A binary tree just says that each node has at max two children, while a binary search tree is a binary tree where the left node is less than the root node, and the root node is less than the right node (whatever "less" may be).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.