Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class myStackReverseTEST {
- public static void main(String[] args) {
- int val;
- myStackReverse<Integer> stack = new myStackReverse<Integer>();
- System.out.println(stack.toString());
- System.out.println(stack.toStringReverse());
- stack.push(new Integer(5));
- System.out.println(stack.toString());
- System.out.println(stack.toStringReverse());
- stack.push(new Integer(10));
- System.out.println(stack.toString());
- System.out.println(stack.toStringReverse());
- stack.push(new Integer(7));
- System.out.println(stack.toString());
- System.out.println(stack.toStringReverse());
- stack.push(new Integer(10));
- System.out.println(stack.toString());
- System.out.println(stack.toStringReverse());
- val = stack.pop();
- System.out.println(stack.toString());
- System.out.println(stack.toStringReverse());
- }
- }
- import java.util.*;
- public class myStackReverse<E> extends Stack<E> {
- public String toStringReverse()
- {
- Stack<E> stack = new Stack<E>();
- Stack<E> revStack = new Stack<E>();
- while (!stack.isEmpty())
- {
- revStack.add(stack.pop());
- }
- return revStack.toString();
- }
- }
- []
- []
- [5]
- []
- [5, 10]
- []
- [5, 10, 7]
- []
- [5, 10, 7, 10]
- []
Add Comment
Please, Sign In to add comment