First off, this question isn't homework. I'm currently reading the book "Data Structures and Algorithms 2nd Edition" by Robert Lafore. In chapter 10, we learned about 2-3-4 trees and are then asked to write a method to find the minimum value in said tree.
From a concept standpoint, I understand where the minimum value is. It is just the left most data item in a leaf.
From a programming standpoint, I'm a little confused on how to implement a method to find this data item. I have a boolean that can tell if the node is a leaf. So what I originally did was this:
public long minValue() {
Node curNode = root; // current node = root
long min = curNode.getMin();
while(!curNode.isLeaf()) { // while current node is NOT a leaf
curNode = getNextChild(curNode, min);
} // end while
return min;
} // end minValue()
What this does (at least what I think it should do, is create a curNode that starts at the root node. Then create a min value that stores curNode.getMin. getMin() just gets the value at the array at index 0 (where the lowest value should be held). Then, while the current node is not a leaf, we should traverse to the next child from the minimum point. Once the current node is a leaf, it should return the minimum value.
This doesn't work though. Does anyone have an idea on how to implement this? Hints or suggestions or anything else?
Edit: To see each of the classes and how they interact, here are links to each separate class. I put the minimum value method in my Tree234 class
DataItem, Node, Tree234, and where the program is run, Tree234App