finding height of a binary search tree without using recursion

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #16
    Originally posted by r035198x
    Public drinking is not allowed in the public forums.
    Admin.
    I wore a brown paper bag over my head so there was nothing public about it. I
    looked and acted just like any other law obedient citizen.

    kind regards,

    Jos ;-)

    Comment

    • AceKnocks
      New Member
      • Jan 2008
      • 14

      #17
      Originally posted by BigDaddyLH
      [CODE=Java]static Node root;
      static int countNode;
      ...

      public BSTree() {
      root = null;
      }
      ...
      public int size () {
      return countNode;
      }

      [/CODE]
      I just noticed that the root and the countNode (tree size) fields are static. What happens when you have another tree?
      Originally posted by JosAH
      Those variables are static because trees themselves don't move either; when will
      people ever learn ...

      kind regards,

      Jos ;-)
      Thanks Jos for defending the objective. In this problem we were not assigned to make multiple BSTrees, rather just one tree which would have all these functions. :)

      As far as writing a non-recursive (loop-iterative) height function is concerned, I could not come up with any and therefore implemented an overridden recursive function in the same class and called that recursive function from this non-recursive function.

      I know that wasn't what I was supposed to do but I didnt have any bright ideas until the very last minute of my submission. Time for a compromise..eh

      Comment

      • BigDaddyLH
        Recognized Expert Top Contributor
        • Dec 2007
        • 1216

        #18
        Originally posted by AceKnocks
        Thanks Jos for defending the objective. In this problem we were not assigned to make multiple BSTrees, rather just one tree which would have all these functions. :)
        I would rethink that, if I were you. You are going out of your way to make your code less general. If you insist on having static data, then all the methods should be made static, and the constructor hidden, because you've given up on a class that is designed to be instantiated.

        Comment

        Working...