I am trying to implement a recursively defined Stack and sort it in Java. I don't have a particular usage of this program in mind. I found this approach of stack implementation a bit useful while implementing persistent stack. I know Stacks are not made for sorting but one can consider using two stacks to implement a job scheduling queue which needs to be sorted for which stacks used for queue implementation must be sorted based on some resource parameters.
Is there any efficient method apart from copying the elements from Stack in array, sorting them and again pushing them on stack? (I know C/C++, Java)
//Stack definition:
Stack
{
E element;
Stack topOfSubStack;
}