Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Homework Edit the following file and save it as Cxxxxxxxx.java where xxxxxxxx is replaced by your 8 digit ID number. Remove any initial package declaration

Homework Edit the following file and save it as Cxxxxxxxx.java where xxxxxxxx is replaced by your 8 digit ID number. Remove any initial package declaration that might be added to your file in case you edit it in eclipse. The goal of the homework is to add an Euler tour traversal (see page 348 of the text) to the implementation of the class BinaryTree that we have considered. Your class Cxxxxxxxx should extend the class BinaryTree and implement just one new method. This file C00000000.java contains a shell for your new class that includes a title line for the method you must code and a main program (based on the BTreeApp demo from class) to check that your method works as it should. The only modifications that you should make are to add one or more methods to the class BinaryTree to provide the traversal method called eulerTour. You should also modify the main method to print your name and 8 digit id number. ********************************************************************/ import java.util.ArrayList; import java.util.Scanner; import class13.BinaryTree; import class13.BNode; public class C00000000 extends BinaryTree { public C00000000() { super(); } public ArrayList> eulerOrder() { return new ArrayList>(); // replace this with code that performs the Euler Tour Traversal } // Demo program to test your method --- change this to display your // name and id number. Also change C00000000 to reflect your ID number. public static void main(String args[]) { C00000000 g = new C00000000<>(); BNode cursor = null; Scanner s = new Scanner(System.in); while (true) { try { System.out.println(g.treePrint(cursor) + " commands act at the *cursor*: E l r X . > < ^ H S Q:"); String cmd = s.next(); if (cmd.charAt(0) == 'E') { ArrayList> tour = g.eulerOrder(); String answer = ""; for (BNode node: tour) answer += node.getData(); System.out.println(answer); } if (cmd.charAt(0) == 'Q') break; if (cmd.charAt(0) == 'H') { System.out.println(g.height()); continue; } if (cmd.charAt(0) == 'S') { System.out.println(g.size()); continue; } if (cmd.charAt(0) == 'X' && cursor != null) { g.removeNode(cursor); cursor = (BNode) g.root(); } if (cmd.charAt(0) == 'l') { String entry = s.next(); if (g.size() > 0) g.addLeft(cursor, entry); else g.addRoot(entry); } if (cmd.charAt(0) == 'r') { String entry = s.next(); if (g.size() > 0) g.addRight(cursor, entry); else g.addRoot(entry); } if (cmd.charAt(0) == '.') cursor = (BNode) g.root(); if (cmd.charAt(0) == '>') cursor = cursor.getRight(); if (cmd.charAt(0) == '<') cursor = cursor.getLeft(); if (cmd.charAt(0) == '^') cursor = (BNode) cursor.getParent(); } catch (Exception e) { System.out.println(e); } } s.close(); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Relational Model A Retrospective Review And Analysis

Authors: C. J. Date

1st Edition

0201612941, 978-0201612943

More Books

Students also viewed these Databases questions

Question

6.11 Describe the key features of koro and dhat syndromes.

Answered: 1 week ago

Question

600 lb 20 0.5 ft 30 30 5 ft

Answered: 1 week ago

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago