Hi, I redefined the toString() method in my own class, but somehow the result is not quite the one I wanted. Sorry for the newbie question, but I can't figure out where the problem is, any advice / hint is mostly appreciated. Thanks.
Myclass:
public class Country implements Comparable<Country>{ private String name; private String capital; private int area; public Country(String a, String b, int c) { this.name = a; this.capital = b; this.area =c; } @Override public String toString(){ return(this.name + " "+ this.capital+" " + this.area); } }
DS:
private void preorder(BinaryNode <type> a){ if (a != null){ System.out.println(a.toString()); preorder(a.left); preorder(a.right ); } }
applications:
BinarySearchTree <Country> db = new BinarySearchTree<Country>(); Country ob = new Country("Romania", "Buc", 123); db.addNewElement(ob); ob = new Country("Hungaria", "Bud", 50); db.addNewElement(ob); ob = new Country("Vatican", "Vat", 1); db.addNewElement(ob); db.printAll();
output:
adt.BinaryNode@1e5e2c3 adt.BinaryNode@18a992f adt.BinaryNode@4f1d0d
EDIT: fix after prompt "chaitanya10" for msitake
DS:
private void preorder(BinaryNode <type> a){ if (a != null){ System.out.println(a.elm.toString());
source share