Just a minor note: you've overlooked the case where the value of the node you're trying to insert is equal to the current node, not strictly greater than or less than the node's value. Either the left or right subtree can be arbitrarily chosen for this, as long as you're consistent.
Full-Stack Software Engineer; using a background in Acting and Voice-Over to pursue a lifelong love of software and technology from an arts and humanities perspective.
Thank you very much for the heads up, Aleksandr! I hadn't considered that case, although it seems quite obvious now that you mention it. I'll keep that in mind moving forward. 👍
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Just a minor note: you've overlooked the case where the value of the node you're trying to insert is equal to the current node, not strictly greater than or less than the node's value. Either the left or right subtree can be arbitrarily chosen for this, as long as you're consistent.
Thank you very much for the heads up, Aleksandr! I hadn't considered that case, although it seems quite obvious now that you mention it. I'll keep that in mind moving forward. 👍