How would you implement a stack with the additional operation of getMin?
Anonymous
I would use two stacks. Pop from 1 to other while checking to see the minimum number. When u r done, re-push from stack2 back to S1 to get the original stack. return minimum. Stack S1; //stack contains data of ints int min=0; //initialize min int Stack::getmin(Stack& S1) { Stack S2; //Transfer all from S1 to S2 while(!S1.isEmpty()) { int temp = S1.pop(); if(temp
Check out your Company Bowl for anonymous work chats.