C How to Program (8th Edition)
C How to Program (8th Edition)
8th Edition
ISBN: 9780133976892
Author: Paul J. Deitel, Harvey Deitel
Publisher: PEARSON
bartleby

Concept explainers

bartleby

Videos

Textbook Question
Book Icon
Chapter 12, Problem 12.24E

(Printing Trees) Write a recursive function outputTree to display a binary tree on the screen. The function should output the tree row-by-row with the top of the tree at the left of the screen and the bottom of the tree toward the right of the screen. Each row is output vertically. For example, the binary tree illustrated in Fig12.22. is output as follows:

Chapter 12, Problem 12.24E, (Printing Trees) Write a recursive function outputTree to display a binary tree on the screen. The

Note that the rightmost leaf node appears at the top of the output in the rightmost column, and the root node appears at the left of the output. Each column of output starts five spaces to the right of the previous column. Function outputTree should receive as arguments a pointer to the root node of the tree and an integer totalSpaces representing the number of spaces preceding the value to be output (this variable should start at zero so that the root node is output at the left of the screen). The function uses a modified inorder traversal to output the tree. The algorithm is as follows:

While the pointer to the current node is not NULL.

Recursively call outputTree with the current node’s right subtree and totalSpaces + 5.

Use a for statement to count from 1to totalSpaces Output the value in the current node.

Recursively call outputTree with the current nodes left subtree and totalSpaces + 5.

Blurred answer
Students have asked these similar questions
2, Towers of Hanoi Problem. (10 points) The Towers of Hanoi is a famous problem for studying recursion in computer science and searching in artificial intelligence. We start with N discs of varying sizes on a peg (stacked in order according to size), and two empty pegs. We are allowed to move a disc from one peg to another, but we are never allowed to move a larger disc on top of a smaller disc. The goal is to move all the discs to the rightmost peg (see figure). To solve the problem by using search methods, we need first formulate the problem. Supposing there are K pegs and N disk. Answer the following questions. (1) Determine a state representation for this problem. (4points) (2) What is the size of the state space? (3 points) (3) Supposing K=3, N=4, what is the start state by using your proposed state representation method and what is the goal state? (3 points)
Language : C
Calculation "a" was used for loop to calculate the sum of squares of values in this list: 1, 7, 8, 6, 11 (The answer was 271) (Question 1) Create recursive function to do the same calculation "a" in the above. (The function input will be the list. Each recursion, you are going to send a sub-list with one less item from the list) (Hint:There are many ways to do sorting. Create a function to perform bubble sorting as descried in this tutorial: (https://www.geeksforgeeks.org/bubble-sort/) . The algorithm should stop when there are no swaps in the last iteration.)

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
Is Java a high-level language or a low-level language?

Java: An Introduction to Problem Solving and Programming (7th Edition)

The ____________ is always transparent.

Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)

The following program will not compile because the lines have been mixed up. System.out.print(Success\n); } pub...

Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)

Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Computational Software for Intelligent System Design; Author: Cadence Design Systems;https://www.youtube.com/watch?v=dLXZ6bM--j0;License: Standard Youtube License