摘要:
Write a program to sort a stack in ascending order. You should not make any assumptions about how the stack is implemented. The following are the only functions that should be used to write this program: push | pop | peek | isEmpty. 1 stack Ssort(stack s){ 2 stack t; 3 while(!s.empty()){ 4 ... 阅读全文
摘要:
How would you design a stack which, in addition to push and pop, also has a function min which returns the minimum element? Push, pop and min should all operate in O(1) time. 1 template 2 class StackWithMin 3 { 4 public: 5 stack() 6 { 7 stackTop = -1; 8 minStackItemIndex = -1... 阅读全文
摘要:
Describe how you could use a single array to implement three stacks. 1 typedef struct Node{ 2 int val,preIdex; 3 Node(int val = INT_MIN,int preIndex=-2):val(val),preIndex(preIndex){} 4 }; 5 6 class Stack3{ 8 public: 9 Stack3(int totalSize = 900){10 buf = new Node[totalSize];11 ... 阅读全文