Wednesday, 1 March 2017

JAVA : STACK Reverse

JAVA : STACK Reverse


1.   public static void main(String[] args){
2.             Stack<Integer> stack = new Stack<Integer>();
3.             stack.push(1);
4.             stack.push(2);
5.             stack.push(3);
6.            
7.             stack = reverseStack(stack);

8.   }

1.   public static Stack<Integer> reverseStack(Stack stack){
2.             Stack<Integer> reverse = new Stack<Integer>();
3.             while(!stack.empty()){
4.                      reverse.push(stack.pop());
5.             }
6.             return reverse;
7.   }









No comments:

Post a Comment