This week's book giveaways are in the Jython/Python and Object-Oriented programming forums.
We're giving away four copies each of Machine Learning for Business: Using Amazon SageMaker and Jupyter and Object Design Style Guide and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning for Business: Using Amazon SageMaker and JupyterE this week in the Jython/Python forum
or Object Design Style Guide in the Object-Oriented programming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

Binary Tree

 
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good day! I took a binary tree quiz and I don't understand what I did wrong in this question. Can somone please tell me why I can't use .equals and how to insert a new node to the correct place?
directions.jpg
[Thumbnail for directions.jpg]
mycode.jpg
[Thumbnail for mycode.jpg]
 
Marshal
Posts: 67533
257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you are doing is setting a new node (left or right), but I can't see where you are retaining the previous branch.
I would query a few things about the assignment. I don't think a char is suitable for determining a direction. All right, two of the potential values are in your method, but what about the other 63354 of them? Why are you using equals()? What sort of variable are you calling equals() on? When you work that out, I think you will see why you can't use equals(). If you have a restricted range of possible arguments, why are you using multiple ifs or if‑elses?
I am puzzled by a method which receives the parameter p. How are you going to find a tree node like that? At least that parameter makes the method easier to write.
Why is the term “child” so popular? I thought trees had branches and leaves.
 
Saloon Keeper
Posts: 6796
64
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
 
Ana Smith
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:equals() is used to compare two objects. A char is a built in type, not an object.



Oh, so instead I should use ==
 
If a regular clown is funny, then a larger clown would be funnier. Math. Verified by this tiny ad:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!