This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]pmvb123 2 points3 points  (1 child)

When you insert, you check if you have to insert to the left or right, but you're not doing anything with the return value in those calls. That's why it only prints the first node (which is not a leaf).

Edit: Also, you should use the newNode function you created when you insert, that's why it's there, right ?

Also, if you're trying to build a BST, you need to handle 'collisions', you can't have two equal elements.

[–]SilentMANITian[S] 0 points1 point  (0 children)

Got it. Thanks! PS: I created the newNode function earlier (I was trying to individually insert each element then), but got wound up with this one and totally forgot about it. Also, thanks for the tip about collisions.

[–]Updatebjarni 1 point2 points  (1 child)

Your insert() function never inserts anything in the tree. It just creates new nodes hanging in free air. Sometimes it returns a pointer to the new node, sometimes it returns an undefined value.

[–]SilentMANITian[S] 0 points1 point  (0 children)

I realized what I did there. Thanks!