Binary Search Tree Traversal

Now, we’ve already seen how to search, insert, and delete data from a binary search tree. I mentioned, though, that we also want to be able to print the entire list of book titles in alphabetical order. How can we do that?

First, we need the ability to visit every single node in the tree. Visiting nodes is just another term for accessing them. The process of visiting every node in a data structure is known as traversing the data structure.

Second, we need to make sure we traverse the tree in alphabetically ascending order so that we can print the list in that order. There are multiple ways to traverse a tree, but for this application, we will perform what is known as inorder traversal, so that we can print each title ...

Get A Common-Sense Guide to Data Structures and Algorithms, Second Edition, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.