Advertisement
Guest User

Untitled

a guest
Nov 26th, 2015
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. import unit4.collectionsLib.Stack;
  2. public class tar2
  3. {
  4. public static int tar2(Stack <Integer> m,int k)
  5. {
  6.  
  7. int a=0;
  8.  
  9. while(!m.isEmpty() && k>=1)
  10. {
  11. a=m.pop();
  12. k--;
  13. }
  14. if(k==0)return a;
  15. else return -1;
  16. }
  17.  
  18. }
  19. ////////////
  20. import unit4.collectionsLib.Stack;
  21. public class main
  22. {
  23. public static void main(String []args)
  24. {
  25. Stack <Integer>m = new Stack<Integer>();
  26. m.push(1);
  27. m.push(2);
  28. m.push(3);
  29. m.push(4);
  30. m.push(5);
  31. m.push(6);
  32. m.push(7);
  33.  
  34.  
  35. System.out.println(tar2.tar2(m,7));
  36. }
  37. }
  38. ///////////////////////////////////////////////////////////
  39. import unit4.collectionsLib.Stack;
  40. public class tar3
  41. {
  42. public static Stack <Integer> tar3(Stack <Integer> a,Stack <Integer> b)
  43. {
  44.  
  45. Stack <Integer> temp=new Stack<Integer>();
  46.  
  47. while(!a.isEmpty() && !b.isEmpty())
  48. {
  49. if(a.top()>b.top() || a.top()==b.top())temp.push(a.pop());
  50. if(a.top()==b.top()){temp.push(a.pop());b.pop();}
  51. else temp.push(b.pop());
  52. }
  53. if(!a.isEmpty())
  54. {
  55. while(!a.isEmpty())
  56. temp.push(a.pop());
  57. }
  58. if(!b.isEmpty())
  59. {
  60. while(!b.isEmpty())
  61. temp.push(a.pop());
  62. }
  63. return temp;
  64. }
  65.  
  66. }
  67. ////////
  68. import unit4.collectionsLib.Stack;
  69. public class main2
  70. {
  71. public static void main2(String []args)
  72. {
  73. Stack <Integer>m = new Stack<Integer>();
  74. Stack <Integer>d = new Stack<Integer>();
  75. m.push(1);
  76. d.push(2);
  77. m.push(3);
  78. d.push(3);
  79. d.push(4);
  80. d.push(5);
  81. m.push(6);
  82. m.push(7);
  83.  
  84.  
  85. System.out.println(tar3.tar3(m,d));
  86. }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement