Advertisement
Guest User

Untitled

a guest
Feb 13th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. package csci.impl;
  2.  
  3. import csci152.adt.Stack;
  4.  
  5. public class Nineth {
  6. public static void main(String[] args) {
  7. Stack<Double> myStack = new LinkedListStack<>();
  8.  
  9. for (int i=0;i<12;i++) {
  10. myStack.push(Double.valueOf(i));
  11. }
  12. myStack.push(1.0);
  13.  
  14. System.out.println(myStack.toString());
  15. //System.out.println(myStack.getSize());
  16.  
  17. System.out.println(isIncreasing(myStack));
  18.  
  19. System.out.println(myStack.toString());
  20. //System.out.println(myStack.getSize());
  21. }
  22. public static boolean isIncreasing (Stack<Double> st) {
  23. Stack<Double> temp = new LinkedListStack<>();
  24. double el;
  25. boolean ans = true;
  26. try {
  27. int i=0;
  28. el = st.pop();
  29. temp.push(el);
  30. int size = st.getSize();
  31. //System.out.println(size);
  32. while (i < size) {
  33. double tempEl = st.pop();
  34. //System.out.println(i);
  35. temp.push(tempEl);
  36. if (tempEl > el) {
  37. ans = false;
  38. }
  39. el = tempEl;
  40. i++;
  41. }
  42. size = temp.getSize();
  43. for (int j = 0; j < size; j++) {
  44. st.push(temp.pop());
  45. }
  46. } catch (Exception e) {
  47. System.out.println(e.getMessage());
  48. }
  49. return ans;
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement