• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Binary Tree

 
Ranch Hand
Posts: 373
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 76462
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 9565
79
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
equals() is used to compare two objects. A char is a built in type, not an object.
 
Ana Smith
Ranch Hand
Posts: 373
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ==
 
Make yourself as serene as a flower, as a tree. And on wednesdays, as serene as this tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic