Binary Search Tree - Duplicates problem
Hey everyone,
I'm having a problem with my binary search tree that allows for duplicates. Duplicates are stored in a linked list which is attached to the original duplicate item node on the tree.
I need to print all the items out including duplicates. I am able to print out all the nodes in the tree via a traversal but this does not include the duplicates contained in the attached linked list. Is it possible to do this all at once or is it best done separately? If so what is the best way to print out a linked list?
Does anyone have any ideas?
Any suggestions would be greatly appreciated. Hope you can help.
Thanks
[660 byte] By [
trellya] at [2007-11-27 6:08:48]

Whenever you traverse the tree, "printing the node" still consists of printing the element stored there, but instead of that being a single element, it's a list of elements. You can write a method that prints all the elements of a list, and then pass the list to that method when traversing. Likewise, when you're searching, instead of returning a single element, return a list of elements, then you can do whatever you want with it, like print it using that handy printList method you wrote earlier. You have to think of the element of a node as any generic object instead of a single specific thing. The element can be a String, a collection of duplicates, an entire new binary search tree, etc. That's fundamental to building complex data structures.