This is a version of the algorithm I have:
public void copyStackToArray(Stack<Integer> stack) {
int i = 0;
while (!this.bestRouteStack.empty()) {
this.array[i++] = stack.pop();
}
}
(the bounds on the array are guaranteed to be okay here for my code)
I'm wondering if there is a library algorithm that does this, but a search turned up nothing.
Stack subclasses Vector which already supports this, try this...
stack.toArray(array)
Here is the Javadoc for this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With