• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Trouble with recursion

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm working on creating an expression tree using recursion. It seems to be building the left side ok but whenever I try to setRight the showSub method does not print the < and prints a / meaning that both either left and right are equal to null and that right is equal to null. I am using the prefix expression *+24-34 and this is what the output looks like.

It should look like something this (the format is a little off since I typed in the correct way it should be written):


I believe the problem is in the buildSub method. I figured if the left side is equal to null I can set it to a digit of the string and when the method runs the buildSub method recursively, it would find that something is contained in the left side and will move to the else if statement and setRight to the next digit of the string. Here is the code:
 
Dustin Schreader
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got it accidently, I commented out some of the code for buildSub but I accidently left the recurloop++; in there and it works now.
 
If you are using a wood chipper, you are doing it wrong. Even on this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic