Guest User

Untitled

a guest
Nov 22nd, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. public class myStackReverseTEST {
  2.  
  3. public static void main(String[] args) {
  4. int val;
  5. myStackReverse<Integer> stack = new myStackReverse<Integer>();
  6. System.out.println(stack.toString());
  7. System.out.println(stack.toStringReverse());
  8. stack.push(new Integer(5));
  9. System.out.println(stack.toString());
  10. System.out.println(stack.toStringReverse());
  11. stack.push(new Integer(10));
  12. System.out.println(stack.toString());
  13. System.out.println(stack.toStringReverse());
  14. stack.push(new Integer(7));
  15. System.out.println(stack.toString());
  16. System.out.println(stack.toStringReverse());
  17. stack.push(new Integer(10));
  18. System.out.println(stack.toString());
  19. System.out.println(stack.toStringReverse());
  20. val = stack.pop();
  21. System.out.println(stack.toString());
  22. System.out.println(stack.toStringReverse());
  23. }
  24.  
  25. }
  26.  
  27. import java.util.*;
  28.  
  29. public class myStackReverse<E> extends Stack<E> {
  30.  
  31. public String toStringReverse()
  32. {
  33. Stack<E> stack = new Stack<E>();
  34. Stack<E> revStack = new Stack<E>();
  35.  
  36. while (!stack.isEmpty())
  37. {
  38. revStack.add(stack.pop());
  39. }
  40.  
  41. return revStack.toString();
  42.  
  43. }
  44. }
  45.  
  46. []
  47. []
  48. [5]
  49. []
  50. [5, 10]
  51. []
  52. [5, 10, 7]
  53. []
  54. [5, 10, 7, 10]
  55. []
Add Comment
Please, Sign In to add comment