QUESTION 4
We discussed using a data structure called a queue to implement level order traversal for binary trees. For example, the level order traversal of the following binary tree would output [10, 5, 20, 3, 8, 12, 30]. Now, please design and implement a function in C++ that takes the root of a tree as input, deletes the entire binary tree, and sets the root to nullptr. You may use a queue for this function, and its time complexity should be O(n).
10
5
20
8
12
30
Attach File
Browse My Computer
Browse Content Collection