Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 18, Problem 18.35PE
Program Plan Intro
H-tree fractal
Program Plan:
- Import required packages.
- Declare a main class named “E35” which extends the “Application” class.
- Declare a “start ()” method which overrides the “start ()” method in the “Application” class. Inside this method,
- Create a pane and a text field.
- Set the action listener for the text field.
- Set the value of the property.
- Set the text field at the bottom right.
- Create a label and add the text field object to the pane.
- Create a border pane.
- Create a scene and place it on the stage.
- Set the title as “Exercise18_35”.
- Display the stage on the window using “primaryStage.show()” method.
- Set the width and height property.
- Declare a class named “HPane”.
- Declare a variable.
- Give function definition to set new order.
- Set the order of the tree.
- Call the function “paint ()”.
- Give function definition for “paint ()”.
- Calculate the width and height.
- Calculate the length.
- Clear the pane using “clear ()” method. Call the function “displayHTree ()”.
- Give function definition for “displayHTree ()”.
- Choose four end points.
- Create three lines.
- Check if the value of “treeOrder” is greater than 0.
- Call the function recursively.
- Declare a main method using “public static main”.
- Launch the method using “launch ()” method.
- Declare a “start ()” method which overrides the “start ()” method in the “Application” class. Inside this method,
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
C++
Recall that a "leaf" node in a binary tree is one which has no child nodes, and the height of a tree is the maximum number of edges from its root to one of its leaves).
We also saw how easily a binary tree can become poorly structured, where the heights to various leaves in the tree vary dramatically.
A full binary tree is one where each node other than the leaf nodes has two child nodes, Write a recursive function which returns true if a binary tree is full, false otherwise. Please avoid the use of variables declared outside of the function.
Given the following infix expression:
(28 * (33 - 3) + 10) / (4 * 0.5) % 4
Give the equivalent postfix expression
Draw the tree corresponding to the recursive calls to evaluate the postfix expression. What is the depth of your tree?
Convert the following postfix statements into expression trees
AB/CD+*
ABCDE+-/+
Chapter 18 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Ch. 18.2 - What is a recursive method? What is an infinite...Ch. 18.2 - Prob. 18.2.2CPCh. 18.2 - Show the output of the following programs and...Ch. 18.2 - Prob. 18.2.4CPCh. 18.2 - Prob. 18.2.5CPCh. 18.2 - Write a recursive mathematical definition for...Ch. 18.3 - Prob. 18.3.1CPCh. 18.3 - What is wrong in the following methods?Ch. 18.3 - Prob. 18.3.3CPCh. 18.4 - Describe the characteristics of recursive methods.
Ch. 18.4 - Prob. 18.4.2CPCh. 18.4 - Prob. 18.4.3CPCh. 18.5 - Prob. 18.5.1CPCh. 18.5 - Prob. 18.5.2CPCh. 18.5 - What is a recursive helper method?Ch. 18.6 - Prob. 18.6.1CPCh. 18.6 - How does the program get all files and directories...Ch. 18.6 - How many times will the getSize method be invoked...Ch. 18.6 - Will the program work if the directory is empty...Ch. 18.6 - Will the program work if line 20 is replaced by...Ch. 18.6 - Will the program work if lines 20 and 21 are...Ch. 18.7 - Prob. 18.7.1CPCh. 18.8 - Prob. 18.8.1CPCh. 18.8 - Prob. 18.8.2CPCh. 18.8 - How many times is the displayTriangles method...Ch. 18.8 - Prob. 18.8.4CPCh. 18.8 - Prob. 18.8.5CPCh. 18.9 - Which of the following statements are true? a. Any...Ch. 18.9 - Prob. 18.9.2CPCh. 18.10 - Identify tail-recursive methods in this chapter.Ch. 18.10 - Rewrite the fib method in Listing 18.2 using tail...Ch. 18 - Prob. 18.1PECh. 18 - Prob. 18.2PECh. 18 - (Compute greatest common divisor using recursion)...Ch. 18 - (Sum series) Write a recursive method to compute...Ch. 18 - (Sum series) Write a recursive method to compute...Ch. 18 - (Sum series) Write a recursive method to compute...Ch. 18 - (Fibonacci series) Modify Listing 18.2,...Ch. 18 - Prob. 18.8PECh. 18 - (Print the characters in a string reversely) Write...Ch. 18 - (Occurrences of a specified character in a string)...Ch. 18 - Prob. 18.11PECh. 18 - (Print the characters in a string reversely)...Ch. 18 - (Find the largest number in an array) Write a...Ch. 18 - (Find the number of uppercase letters in a string)...Ch. 18 - Prob. 18.15PECh. 18 - (Find the number of uppercase letters in an array)...Ch. 18 - (Occurrences of a specified character in an array)...Ch. 18 - (Tower of Hanoi) Modify Listing 18.8,...Ch. 18 - Prob. 18.19PECh. 18 - (Display circles) Write a Java program that...Ch. 18 - (Decimal to binary) Write a recursive method that...Ch. 18 - (Decimal to hex) Write a recursive method that...Ch. 18 - (Binary to decimal) Write a recursive method that...Ch. 18 - (Hex to decimal) Write a recursive method that...Ch. 18 - Prob. 18.25PECh. 18 - (Create a maze) Write a program that will find a...Ch. 18 - (Koch snowflake fractal) The text presented the...Ch. 18 - (Nonrecursive directory size) Rewrite Listing...Ch. 18 - (Number of files in a directory) Write a program...Ch. 18 - (Game: Knights Tour) The Knights Tour is an...Ch. 18 - (Game: Knights Tour animation) Write a program for...Ch. 18 - (Game: Eight Queens) The Eight Queens problem is...Ch. 18 - Prob. 18.35PECh. 18 - (Sierpinski triangle) Write a program that lets...Ch. 18 - (Hilbert curve) The Hilbert curve, first described...Ch. 18 - (Recursive tree) Write a program to display a...Ch. 18 - Prob. 18.39PE
Knowledge Booster
Similar questions
- C++, Write a recursion function that counts the positive elements multiple of 5 in a binary search tree and counts the elements less than 0 and multiple of 2, then returns the two counts multiplied to the main.Note that you have to write only one function and you can add parameters to the function as neededarrow_forwardLook for 5 examples of expressions, then put in a Binary Representation Tree, including the Prefix and Postfix expressions. Show solution.arrow_forwardComputer Science Convert the following expressions to both Prefix and Postfix / Infix and create the binary trees which represent them. A. P * (Q + R) + S / T * W - X * Y + Z B. (A + B) * (C + D * E) / F / G / H+I C. J K L $ * M N - P * + Q R * - S +arrow_forward
- SOLVE THE MAZE FUNCTION USING STACK.PLEASE ONLY C CODE,DONT USE C++ AND C#. /* R\C 0 1 2 3 4 5 6 7 *//* 0 */ {0, 0, 0, 1, 0, 0, 0, 0},/* 1 */ {0, 1, 1, 1, 0, 0, 1, 0},/* 2 */ {0, 1, 0, 1, 0, 0, 1, 0},/* 3 */ {0, 1, 0, 1, 1, 1, 1, 0},/* 4 */ {0, 1, 0, 0, 0, 0, 1, 1},/* 5 */ {0, 1, 1, 0, 1, 1, 1, 0},/* 6 */ {0, 0, 0, 0, 1, 0, 0, 0},/* 7 */ {0, 0, 0, 0, 1, 0, 0, 0}, #include <stdio.h>#include <stdlib.h>#include <string.h> typedef struct LINKED_STACK_NODE_s *LINKED_STACK_NODE; typedef struct LINKED_STACK_NODE_s{LINKED_STACK_NODE next;void *data;} LINKED_STACK_NODE_t[1]; typedef struct LINKED_STACK_s{LINKED_STACK_NODE head;int count;} LINKED_STACK_t[1], *LINKED_STACK; typedef struct{int R;int C;} POS_t[1], *POS; LINKED_STACK stack_init();void stack_free(LINKED_STACK stack);void stack_push(LINKED_STACK stack, void *data);void *stack_pop(LINKED_STACK stack);void *stack_top(LINKED_STACK stack);int is_empty(LINKED_STACK stack); int is_empty(LINKED_STACK stack){return…arrow_forwardSolve the maze function using stack.PLEASE ONLY C CODE, DONT USE C++ AND C# . /* R\C 0 1 2 3 4 5 6 7 *//* 0 */ {0, 0, 0, 1, 0, 0, 0, 0},/* 1 */ {0, 1, 1, 1, 0, 0, 1, 0},/* 2 */ {0, 1, 0, 1, 0, 0, 1, 0},/* 3 */ {0, 1, 0, 1, 1, 1, 1, 0},/* 4 */ {0, 1, 0, 0, 0, 0, 1, 1},/* 5 */ {0, 1, 1, 0, 1, 1, 1, 0},/* 6 */ {0, 0, 0, 0, 1, 0, 0, 0},/* 7 */ {0, 0, 0, 0, 1, 0, 0, 0}, void solve_maze(){int M[8][8] = {/* R\C 0 1 2 3 4 5 6 7 *//* 0 */ {0, 0, 0, 1, 0, 0, 0, 0},/* 1 */ {0, 1, 1, 1, 0, 0, 1, 0},/* 2 */ {0, 1, 0, 1, 0, 0, 1, 0},/* 3 */ {0, 1, 0, 1, 1, 1, 1, 0},/* 4 */ {0, 1, 0, 0, 0, 0, 1, 1},/* 5 */ {0, 1, 1, 0, 1, 1, 1, 0},/* 6 */ {0, 0, 0, 0, 1, 0, 0, 0},/* 7 */ {0, 0, 0, 0, 1, 0, 0, 0},};int I, J, R = 0, C = 3;LINKED_STACK stack;POS pos = (POS)malloc(sizeof(POS));int flag;stack = stack_init(); do{// TODO: Fill this block.} while (R != 7 && C != 7 && R != 0 && C != 0);}int main(){solve_maze();return 0;}arrow_forwardWrite a C++ code to insert the following information in the Binary Search Tree: {Paris, London, Dubai, Muscat, Riyadh, Berlin, Amsterdam, Sydney, Stockholm, Oslo} After insertion, print all names of binary search tree using cout statement.arrow_forward
- Problem Statement: (The following problem is based on a problem in a number of Java texts, including the text by Gaddis.) Given a numeric expression in prefix form, develop a Java program to evaluate the expression. ================================================================================ NOTE 1: Your program should internally convert the prefix expression into a binary tree before evaluating it Feel free to use any other data structures, in addition to the binary tree, that you may deem necessary to set up and evaluate your prefix expression ================================================================================ The following site provides some explanation on prefix expressions, as well as other forms of numeric expressions: Infix, Prefix and Postfix Expressions (Links to an external site.) Input Data: Repeatedly, enter one prefix expression (as a string) at a time at the keyboard alternatively, you may set up an input data file and get the data from the…arrow_forwardAnswer (iii) with detailed and concise explanations. Give the content of the stack after each of the following operations takes place.arrow_forwardAnswer the following questions using python and without using any of its libraries or OOP . a) Using the helper function insert (bst, key), create the binary search tree that results from inserting the following keys in the order given: 68, 88, 61, 89, 94, 50, 4, 76, 66, and 82. b) Using the helper function exist (bst, key), check whether key 50 exists in resultant Binary Search Tree. c) Using the helper function exist (bst, key), check whether key 49 exists in resultant Binary Search Tree. d) Using the helper function minimum (bst, starting_node), find the node with the minimum value in resultant Binary Search Tree from starting node = 68. e) Using the helper function minimum (bst, starting_node), find the node with the minimum value in resultant Binary Search Tree from starting node = 88. f) Using the helper function maximum (bst, starting_node), find the node with the maximum value in resultant Binary Search Tree from starting node = 68. g) Using the helper function maximum (bst,…arrow_forward
- Draw the recursion tree:arrow_forwardplease answer in scheme racket flavor 1. Create the recursive function far-left that will find the left-most value 2.Create the recursive function far-right that will find right-most value 3. Write depth, a procedure that takes a tree as an argument and returns the largest number of nodes connected through parent-child links. That is, a leaf node has depth 1; a tree in which all the children of the root node are leaves has depth 2. Our world tree has depth 4 (because the longest path from the root to a leaf is, for example, world, country, state, city). 4. Write count-nodes, a procedure that takes a tree as an argument and returns the total number of nodes in the tree. (Earlier we counted the number of leaf nodes.) (define (leaf? node) (null? (children node))) (define (datum node) (car node)) (define (children node) (cdr node)) (define (count-leaves tree) (if (leaf? tree) 1 (count-leaves-in-forest (children tree)) ) ) (define (count-leaves-in-forest forest) (if (null? forest) 0 (+…arrow_forwardWrite a function same_shape : 'a tree -> 'b tree -> bool that determines whether two trees have the same shape, regardless of whether the values they carry at each node are the same. Hint: use a pattern match with three branches, where the expression being matched is a pair of trees.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning