• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Binary Expression Tree

 
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, I am trying to finish up this last part of the binary tree and I just cant seem to get it. According to the instructor theres something wrong in my right parentheses case. Here is the algorithm for the right paren I was following.
The output for pre, post and in I get "-" when my expression is ((3 * (8 - 2)) - (1 + 9))"


Case RPAREN:

if (stack is not empty)  
assign current node to child                        
pop stack and assign to currentNode                        
if (currentNode.Left is null)                            
assign child to currentNode.Left                        
else if currentNode.Right is null                            
assign child to right node                        
else                            
unexpected – generate error                        
end if                    
end if                
end case

Here is my right paren code



and the whole class just to show
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So made some changes. gets me closer, but still not what I want.

Right paren case is now


and number case is

 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Solved it....Just need to slow down and look carefully at what the program is asking.

full fixed class just in case anyone saw this, and was thinking

 
reply
    Bookmark Topic Watch Topic
  • New Topic