give me c++ code Program for ternary tree Problem Statement: You are an archivist tasked…
- User
give me c++ code Program for ternary tree Problem Statement: You are an archivist tasked with managing a magical archive where each document is stored in a Ternary Tree. The tree nodes are sorted by their magical potency, where each document has three potential connections: • Left child: Less potent. • Middle child: Equal potency. Right child: More potent. For various kinds of research, the archivist must retrieve documents based on their position in the tree. Specifically: Documents on odd-numbered levels are retrieved in ascending order. Documents on even-numbered levels are retrieved in descending order. He archivist has asked you to create a program that will take in the documents' potency levels and return the documents at either the odd or even levels, sorted in the appropriate order. Problem:
- You will be given a number n, representing the number of documents in the archive.
- You will then be given n integers representing the potency levels of the documents to be inserted into the ternary tree.
- Finally, you will be asked to print the documents from either the odd levels (ascending) or the even levels (descending). Input Format: • First, an integer n representing the number of documents (nodes). Second, n integers representing the potency levels of the documents space separated. Third, the string "odd" or "even", indicating which level's documents to print. Output Format: • If "odd" is chosen, print the document potency levels at odd levels in ascending order. • If "even" is chosen, print the document potency levels at even levels in descending order. Sample Test Cases Test Case 1: Expected Output: 6 175294 odd 1-4-5-9- Test Case 2: Expected Output: 5 16423 even 6-2-
- Assistant