*Author

Offline Drake_XIVTopic starter

  • Legendary Member
  • ******
  • Posts: 6929
  • Country: us
  • Reputation Power: 91
  • Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.
  • Powerful Harmony
  • Awards: Slice of Elements 10th Birthday CakeSlice of Elements 6th Birthday CakeSummer and Winter Competition WinnerSlice of Elements 4th Birthday CakeSlice of Elements 3rd Birthday Cake
JAVA toString() Override http://elementscommunity.org/forum/index.php?topic=57023.msg1170421#msg1170421
« on: December 09, 2014, 04:48:07 pm »
I asked this earlier in chat, but what happens if I'm calling a toString method when two exist?

In the classes below, I intend on adding the following method findMin() to the BinarySearchTree class.

Code: [Select]
   public void findMin()
   {
   Node min = root;
   if(root.left != null)
   min = root.left;
   System.out.println("The smallest node is: " + min);
   }

My question is that assuming I set root to hold object type Author by setting Node root = Author example, when the print calls min.toString(), will it be the default toString() [which returns a hashcode]? Or will it call Author.toString(), returning the toString() method defined in the Author class?

For reference, I've included the two classes below.
« Last Edit: December 09, 2014, 04:54:37 pm by Drake_XIV »

Offline Drake_XIVTopic starter

  • Legendary Member
  • ******
  • Posts: 6929
  • Country: us
  • Reputation Power: 91
  • Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.
  • Powerful Harmony
  • Awards: Slice of Elements 10th Birthday CakeSlice of Elements 6th Birthday CakeSummer and Winter Competition WinnerSlice of Elements 4th Birthday CakeSlice of Elements 3rd Birthday Cake
Re: JAVA toString Override http://elementscommunity.org/forum/index.php?topic=57023.msg1170422#msg1170422
« Reply #1 on: December 09, 2014, 04:48:19 pm »
Code: [Select]
/**
   This class implements a binary search tree whose
   nodes hold objects that implement the Comparable
   interface.
*/
public class BinarySearchTree

   private Node root;

   /**
      Constructs an empty tree.
   */
   public BinarySearchTree()
   { 
      root = null;
   }
   
   /**
      Inserts a new node into the tree.
      @param obj the object to insert
   */
   public void add(Comparable obj)
   { 
      Node newNode = new Node();
      newNode.data = obj;
      newNode.left = null;
      newNode.right = null;
      if (root == null) { root = newNode; }
      else { root.addNode(newNode); }
   }

   /**
      Tries to find an object in the tree.
      @param obj the object to find
      @return true if the object is contained in the tree
   */
   public boolean find(Comparable obj)
   {
      Node current = root;
      while (current != null)
      {
         int d = current.data.compareTo(obj);
         if (d == 0) { return true; }
         else if (d > 0) { current = current.left; }
         else { current = current.right; }
      }
      return false;
   }
   
   /**
      Tries to remove an object from the tree. Does nothing
      if the object is not contained in the tree.
      @param obj the object to remove
   */
   public void remove(Comparable obj)
   {
      // Find node to be removed

      Node toBeRemoved = root;
      Node parent = null;
      boolean found = false;
      while (!found && toBeRemoved != null)
      {
         int d = toBeRemoved.data.compareTo(obj);
         if (d == 0) { found = true; }
         else
         {
            parent = toBeRemoved;
            if (d > 0) { toBeRemoved = toBeRemoved.left; }
            else { toBeRemoved = toBeRemoved.right; }
         }
      }

      if (!found) { return; }

      // toBeRemoved contains obj

      // If one of the children is empty, use the other

      if (toBeRemoved.left == null || toBeRemoved.right == null)
      {
         Node newChild;
         if (toBeRemoved.left == null)
         {
            newChild = toBeRemoved.right;
         }
         else
         {
            newChild = toBeRemoved.left;
         }

         if (parent == null) // Found in root
         {
            root = newChild;
         }
         else if (parent.left == toBeRemoved)
         {
            parent.left = newChild;
         }
         else
         {
            parent.right = newChild;
         }
         return;
      }
     
      // Neither subtree is empty

      // Find smallest element of the right subtree

      Node smallestParent = toBeRemoved;
      Node smallest = toBeRemoved.right;
      while (smallest.left != null)
      {
         smallestParent = smallest;
         smallest = smallest.left;
      }

      // smallest contains smallest child in right subtree
         
      // Move contents, unlink child

      toBeRemoved.data = smallest.data;
      if (smallestParent == toBeRemoved)
      {
         smallestParent.right = smallest.right;
      }
      else
      {
         smallestParent.left = smallest.right;
      }
   }
   
   /**
      Prints the contents of the tree in sorted order.
   */
   public void print()
   { 
      print(root);
      System.out.println();
   } 

   /**
      Prints a node and all of its descendants in sorted order.
      @param parent the root of the subtree to print
   */
   private static void print(Node parent)
   { 
      if (parent == null) { return; }
      print(parent.left);
      System.out.print(parent.data + " ");
      print(parent.right);
   }

   /**
      A node of a tree stores a data item and references
      to the left and right child nodes.
   */
   class Node
   { 
      public Comparable data;
      public Node left;
      public Node right;

      /**
         Inserts a new node as a descendant of this node.
         @param newNode the node to insert
      */
      public void addNode(Node newNode)
      { 
         int comp = newNode.data.compareTo(data);
         if (comp < 0)
         { 
            if (left == null) { left = newNode; }
            else { left.addNode(newNode); }
         }
         else if (comp > 0)
         { 
            if (right == null) { right = newNode; }
            else { right.addNode(newNode); }
         }
      }
   }
}

Offline Drake_XIVTopic starter

  • Legendary Member
  • ******
  • Posts: 6929
  • Country: us
  • Reputation Power: 91
  • Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.
  • Powerful Harmony
  • Awards: Slice of Elements 10th Birthday CakeSlice of Elements 6th Birthday CakeSummer and Winter Competition WinnerSlice of Elements 4th Birthday CakeSlice of Elements 3rd Birthday Cake
Re: JAVA toString Override http://elementscommunity.org/forum/index.php?topic=57023.msg1170423#msg1170423
« Reply #2 on: December 09, 2014, 04:48:40 pm »
Code: [Select]
/* This class is used to illustrate the Comparable interface */
/* It also overrides equals(),hashCode(), toString() */

class Author implements Comparable<Author>{
    String firstName;
    String lastName;
/* Constructor */
    public Author(String inlast, String infirst)
    {
lastName=inlast;
firstName=infirst;
}

// compareTo should return < 0 if this is supposed to be
// less than other, > 0 if this is supposed to be greater than
// other and 0 if they are supposed to be equal
    public int compareTo(Author other)
    {
        if (this.lastName.equals(other.lastName))
return (this.firstName.compareTo(other.firstName));
        else
return (this.lastName.compareTo(other.lastName));
    }

/* equals() returns true if both the lastname and the firstname are the same */
    public boolean equals(Author other)
    {
    if (this.lastName.equals(other.lastName) && this.firstName.equals(other.firstName))
return true;
else
return false;
}

/* hashCode() returns the sum of the individual Strings' hashCode() values */
public int hashCode()
{
return lastName.hashCode()+firstName.hashCode();
}

public String toString()
{
// return "The author's name is: " + firstName + " " + lastName;

// changing toString for purpose of output
return firstName + " " + lastName;
}
}

Offline CuCN

  • Hero Member
  • *****
  • Posts: 1756
  • Reputation Power: 25
  • CuCN is a proud Wyrm taking wing for the first time.CuCN is a proud Wyrm taking wing for the first time.CuCN is a proud Wyrm taking wing for the first time.CuCN is a proud Wyrm taking wing for the first time.CuCN is a proud Wyrm taking wing for the first time.
  • Toxic
  • Awards: Slice of Elements 5th Birthday CakeSlice of Elements 4th Birthday Cake
Re: JAVA toString() Override http://elementscommunity.org/forum/index.php?topic=57023.msg1170425#msg1170425
« Reply #3 on: December 09, 2014, 05:01:14 pm »
Code: [Select]
public class Class1{
    private static class Class2{
        private String name="x";
        public String toString(){
            return name;
        }
    }
    public static void main(String... __){
        Object a=new Class2();
        System.out.println(a.toString());
    }
}

I tried this and it printed "x".

Offline UTAlan

  • Hero Member
  • *****
  • Posts: 1802
  • Reputation Power: 58
  • UTAlan is truly a Titan, worthy of respect and acknowledgement.UTAlan is truly a Titan, worthy of respect and acknowledgement.UTAlan is truly a Titan, worthy of respect and acknowledgement.UTAlan is truly a Titan, worthy of respect and acknowledgement.UTAlan is truly a Titan, worthy of respect and acknowledgement.UTAlan is truly a Titan, worthy of respect and acknowledgement.UTAlan is truly a Titan, worthy of respect and acknowledgement.UTAlan is truly a Titan, worthy of respect and acknowledgement.UTAlan is truly a Titan, worthy of respect and acknowledgement.UTAlan is truly a Titan, worthy of respect and acknowledgement.UTAlan is truly a Titan, worthy of respect and acknowledgement.
  • Immortally Aether
  • Awards: Slice of Elements 9th Birthday CakeSlice of Elements 8th Birthday CakeSlice of Elements 7th Birthday CakeWeekly Tournament WinnerSlice of Elements 6th Birthday CakeReviver of the WikiWar #6 Winner - Team AetherSlice of Elements 3rd Birthday CakeSecond Budosei of BudokanSlice of Elements 2nd Birthday CakeWeekly Tournament Winner
Re: JAVA toString() Override http://elementscommunity.org/forum/index.php?topic=57023.msg1170431#msg1170431
« Reply #4 on: December 09, 2014, 05:17:03 pm »
And yet I ran the original code above and got a hash.

Offline UTAlan

  • Hero Member
  • *****
  • Posts: 1802
  • Reputation Power: 58
  • UTAlan is truly a Titan, worthy of respect and acknowledgement.UTAlan is truly a Titan, worthy of respect and acknowledgement.UTAlan is truly a Titan, worthy of respect and acknowledgement.UTAlan is truly a Titan, worthy of respect and acknowledgement.UTAlan is truly a Titan, worthy of respect and acknowledgement.UTAlan is truly a Titan, worthy of respect and acknowledgement.UTAlan is truly a Titan, worthy of respect and acknowledgement.UTAlan is truly a Titan, worthy of respect and acknowledgement.UTAlan is truly a Titan, worthy of respect and acknowledgement.UTAlan is truly a Titan, worthy of respect and acknowledgement.UTAlan is truly a Titan, worthy of respect and acknowledgement.
  • Immortally Aether
  • Awards: Slice of Elements 9th Birthday CakeSlice of Elements 8th Birthday CakeSlice of Elements 7th Birthday CakeWeekly Tournament WinnerSlice of Elements 6th Birthday CakeReviver of the WikiWar #6 Winner - Team AetherSlice of Elements 3rd Birthday CakeSecond Budosei of BudokanSlice of Elements 2nd Birthday CakeWeekly Tournament Winner
Re: JAVA toString() Override http://elementscommunity.org/forum/index.php?topic=57023.msg1170432#msg1170432
« Reply #5 on: December 09, 2014, 05:27:21 pm »
Ah. Node has a toString(), and node.data has a toString(). If you change the findMin() method to use this:

Code: [Select]
System.out.println("The smallest node is: " + min.data);
It prints the Author's name.

Offline Drake_XIVTopic starter

  • Legendary Member
  • ******
  • Posts: 6929
  • Country: us
  • Reputation Power: 91
  • Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.
  • Powerful Harmony
  • Awards: Slice of Elements 10th Birthday CakeSlice of Elements 6th Birthday CakeSummer and Winter Competition WinnerSlice of Elements 4th Birthday CakeSlice of Elements 3rd Birthday Cake
Re: JAVA toString() Override http://elementscommunity.org/forum/index.php?topic=57023.msg1170433#msg1170433
« Reply #6 on: December 09, 2014, 05:28:10 pm »
I realized that the method I included in the first post needed to loop, so I changed the method to:

Code: [Select]
   public void findMin()
   {
   boolean go = true;
   while(go)
   {
   Node min = root;
   if(min.left == null)
   {
   go = false;
   System.out.println("The smallest node is: " + min);
   }
   else
   {
   min = min.left;
   }
   }
   }

But it's still returning a hash.

I know from my implementation that all nodes either have Author or null as their data. So for when I call a node, is there a way that I can have it treated as Object type Author?

EDIT- Will check .data . I feel stupid for forgetting about that.

Offline Drake_XIVTopic starter

  • Legendary Member
  • ******
  • Posts: 6929
  • Country: us
  • Reputation Power: 91
  • Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.
  • Powerful Harmony
  • Awards: Slice of Elements 10th Birthday CakeSlice of Elements 6th Birthday CakeSummer and Winter Competition WinnerSlice of Elements 4th Birthday CakeSlice of Elements 3rd Birthday Cake
Re: JAVA toString() Override http://elementscommunity.org/forum/index.php?topic=57023.msg1170435#msg1170435
« Reply #7 on: December 09, 2014, 05:33:11 pm »
Yeah. Definitely feel stupid now. data fixed the print issue. But now I have an issue with with findMin running forever. I have method findMax that is the same, just changing min > max and .left > .right and that method works fine.

Offline Drake_XIVTopic starter

  • Legendary Member
  • ******
  • Posts: 6929
  • Country: us
  • Reputation Power: 91
  • Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.
  • Powerful Harmony
  • Awards: Slice of Elements 10th Birthday CakeSlice of Elements 6th Birthday CakeSummer and Winter Competition WinnerSlice of Elements 4th Birthday CakeSlice of Elements 3rd Birthday Cake
Re: JAVA toString() Override http://elementscommunity.org/forum/index.php?topic=57023.msg1170436#msg1170436
« Reply #8 on: December 09, 2014, 05:33:41 pm »
Code: [Select]
   public void findMax()
   {
   boolean go = true;
   while(go)
   {
   Node max = root;
   if(max.right == null)
   {
   go = false;
   System.out.println("The largest node is: " + max.data);
   }
   else
   {
   max = max.right;
   }
   }
   }

Offline UTAlan

  • Hero Member
  • *****
  • Posts: 1802
  • Reputation Power: 58
  • UTAlan is truly a Titan, worthy of respect and acknowledgement.UTAlan is truly a Titan, worthy of respect and acknowledgement.UTAlan is truly a Titan, worthy of respect and acknowledgement.UTAlan is truly a Titan, worthy of respect and acknowledgement.UTAlan is truly a Titan, worthy of respect and acknowledgement.UTAlan is truly a Titan, worthy of respect and acknowledgement.UTAlan is truly a Titan, worthy of respect and acknowledgement.UTAlan is truly a Titan, worthy of respect and acknowledgement.UTAlan is truly a Titan, worthy of respect and acknowledgement.UTAlan is truly a Titan, worthy of respect and acknowledgement.UTAlan is truly a Titan, worthy of respect and acknowledgement.
  • Immortally Aether
  • Awards: Slice of Elements 9th Birthday CakeSlice of Elements 8th Birthday CakeSlice of Elements 7th Birthday CakeWeekly Tournament WinnerSlice of Elements 6th Birthday CakeReviver of the WikiWar #6 Winner - Team AetherSlice of Elements 3rd Birthday CakeSecond Budosei of BudokanSlice of Elements 2nd Birthday CakeWeekly Tournament Winner
Re: JAVA toString() Override http://elementscommunity.org/forum/index.php?topic=57023.msg1170438#msg1170438
« Reply #9 on: December 09, 2014, 05:38:09 pm »
Throw in some println's and see what's happening. In the while, before the if-else.

Offline Drake_XIVTopic starter

  • Legendary Member
  • ******
  • Posts: 6929
  • Country: us
  • Reputation Power: 91
  • Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.Drake_XIV is a mythical and divine giver of immortality, one of the Turquoise Nymphs.
  • Powerful Harmony
  • Awards: Slice of Elements 10th Birthday CakeSlice of Elements 6th Birthday CakeSummer and Winter Competition WinnerSlice of Elements 4th Birthday CakeSlice of Elements 3rd Birthday Cake
Re: JAVA toString() Override http://elementscommunity.org/forum/index.php?topic=57023.msg1170442#msg1170442
« Reply #10 on: December 09, 2014, 05:51:41 pm »
It's not even returning anything when I do, so I guess it's not recursive issues [having it print min.data].

What I'm seeing with recreating this in the findMax method is that it's starting at the intended solution. While this is good for output, I'm concerned with how the logic in the nodes is going.
« Last Edit: December 09, 2014, 05:53:58 pm by Drake_XIV »

Offline Legit

  • Sr. Member
  • ****
  • Posts: 791
  • Reputation Power: 18
  • Legit is a Blue Crawler starting to think about his first run.Legit is a Blue Crawler starting to think about his first run.Legit is a Blue Crawler starting to think about his first run.
  • Laxydaxy drives a taxi
  • Awards: Weekly Tournament WinnerWar #3 Winner - Team FirePsuedo-Element Winner (Tech)
Re: JAVA toString() Override http://elementscommunity.org/forum/index.php?topic=57023.msg1170458#msg1170458
« Reply #11 on: December 09, 2014, 06:58:11 pm »
Yeah. Definitely feel stupid now. data fixed the print issue. But now I have an issue with with findMin running forever. I have method findMax that is the same, just changing min > max and .left > .right and that method works fine.

Look closely at where you are declaring your variables. What is happening during every iteration of the while loop?

 

anything
blarg: