1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
NNADVOKAT [17]
3 years ago
10

Write a method equals that could be added to the IntTree class. (On your handout this method is called "equals", but Practice-It

needs to use the name "equals" for another purpose, so we'll call it "equals2" here.) The method accepts another binary tree of integers as a parameter and compares the two trees to see if they are equal to each other. For example, if variables of type IntTree called t1 and t2 have been initialized, then the call of t1.equals2(t2) will return true if the trees are equal and false if otherwise.Two trees are considered equal if they have exactly the same structure and store the same values. Each node in one tree must have a corresponding node in the other tree in the same location relative to the root and storing the same value. Two empty trees are considered equal to each other.You may define private helper methods to solve this problem, but otherwise you may not call any other methods of the class nor create any data structures such as arrays, lists, etc. Your method should not change the structure or contents of either of the two trees being compared.Assume that you are adding this method to the IntTree class as defined below:public class IntTree { private IntTreeNode overallRoot; ...}
Computers and Technology
1 answer:
masya89 [10]3 years ago
6 0

Answer:

public boolean equals(Object other)

{

// check correct instance

if (other instanceof IntTree)

{

try

{

IntTree otherTree = (IntTree) other;

return equals(overallRoot, otherTree.overallRoot);

}

// caught exceptions

catch (Exception e)

{

return false;

}

}

return false;

}

public boolean equals(IntTreeNode tree1, IntTreeNode tree2)

{

// if reach ends

if (tree1 == null && tree2 == null)

{

// they are equal

return true;

}

else if (tree1 == null || tree2 == null)

{

// not equal

return false;

}

// check left part

boolean leftPart = equals(tree1.left, tree2.left);

// check current element is same

boolean currentPart = tree1.element.equals(tree2.element);

// check right part

boolean rightPart = equals(tree1.right, tree2.right);

// all are equal

return (leftPart && currentPart && rightPart);

}

Explanation:

You might be interested in
a document contains a list of items that appear in no particular order. what is the best way to format the list
krok68 [10]

Answer:

bulleted list

Explanation:

8 0
3 years ago
Which of the following file formats allows you to share and save documents
mariarad [96]
OPTION A would be the answer
7 0
2 years ago
Most hard drives are divided into sectors of 512 bytes each. Our disk has a size of 16 GB. Fill in the blank to calculate how ma
nika2105 [10]
The answer is pretty simple to achieve for this question. Multiply the disk size and then divide by the sector size - this will result in the total number of sectors. The reason the disk size shows “16*1024*1024*1024” is because there are 1024 bytes (B) in one kilobyte (1KB), and 1024KB in one megabyte (1MB), and 1024MB in one gigabyte (1GB). So, once you find out how many total bytes you have and then divide the total number of bytes by sector size (512), you will arrive at the answer.
4 0
3 years ago
Match these items. 1 . Naturalization Act stated that a foreigner had to live in the United States fourteen years to become a ci
Romashka-Z-Leto [24]

Answer and Explanation:

1. Naturalization Act:

  • Expressed that an outsider needed to live in the United States fourteen years to turn into a native.

2. Judiciary Act:

  • It was an effort to save Federalist standards

3. Sedition Act:

  • Approved fines up to $5,000 and detainment for ruining the legislature.

4. Alien Act:

  • Allowed the President to oust aliens or outsiders whom he judged "risky"

5. Alien and Sedition Acts:

  • Constrained through Congress by the Federalists.

6. Alien Enemies Act:

  • Allowed the President to detain or extradite hazardous outsiders or aliens in time of war
8 0
3 years ago
#Write a function called hide_and_seek. The function should #have no parameters and return no value; instead, when #called, it s
Arlecino [84]

Answer:

# hide_and_seek function is defined

def hide_and_seek():

# for loop from 1 to 10

# and print each number

for number in range(1, 11):

print(number)

# the last message is displayed on its own line

print("Ready or not, here I come!")

# the function is called

hide_and_seek()

Explanation:

The code is well commented. A sample image of the output when the code is executed is attached.

7 0
3 years ago
Other questions:
  • What does the security element of non-repudiation mean in e-commerce cybersecurity? A. Data needs to be available at all times.
    10·1 answer
  • Discuss the important basic building blocks required to create a web page in HTML/XHTML. Discuss how to place CSS rules within y
    15·1 answer
  • Morgan's cursor is blinking in the center of the page but he would like to move it to the left margin. He should _____.
    10·1 answer
  • What component of a computer system holds the operating system when the computer is not running
    6·2 answers
  • Write a C function which mimics the behavior of the assembly language function below. Note that this time, the assembly language
    10·1 answer
  • What are the long-term consequences for John’s health and wellness if he continues to use this technique
    15·1 answer
  • Write a python program to calculate the average of two numbers​
    8·1 answer
  • Write a function named minMax() that accepts three integers arguments from the keyboard and finds the smallest and largest integ
    5·1 answer
  • The CTRL, ALT, and WINDOWS keys are commonly used for keyboard shortcuts, which are keystrokes that can quickly perform an opera
    9·1 answer
  • What type of programing code do game developers use.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!