• Post Reply Bookmark Topic Watch Topic
  • New Topic

How do I change a variable that is in the main from inside of a method?  RSS feed

 
Michael Ferguson
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm working on a RedBlack Tree program for a data structures class in college. I'm doing some rotations after insertions, but when I print my tree it is incorrect because I am failing to update the root of the tree when the root is part of the rotation. I want to change the root based on the rotation that occurs inside the method, but I am unsure how to go about doing this. When I try to blatantly set the root inside the method, I get the obvious cannot find symbol error. Any help?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Short answer: you can't. If the variable is declared in the method, it's scope is that method and therefore isn't visible anywhere else.

What you probably should be doing is passing an object into your method, and using the object's methods to update values.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!