Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import unit4.collectionsLib.Stack;
- public class tar2
- {
- public static int tar2(Stack <Integer> m,int k)
- {
- int a=0;
- while(!m.isEmpty() && k>=1)
- {
- a=m.pop();
- k--;
- }
- if(k==0)return a;
- else return -1;
- }
- }
- ////////////
- import unit4.collectionsLib.Stack;
- public class main
- {
- public static void main(String []args)
- {
- Stack <Integer>m = new Stack<Integer>();
- m.push(1);
- m.push(2);
- m.push(3);
- m.push(4);
- m.push(5);
- m.push(6);
- m.push(7);
- System.out.println(tar2.tar2(m,7));
- }
- }
- ///////////////////////////////////////////////////////////
- import unit4.collectionsLib.Stack;
- public class tar3
- {
- public static Stack <Integer> tar3(Stack <Integer> a,Stack <Integer> b)
- {
- Stack <Integer> temp=new Stack<Integer>();
- while(!a.isEmpty() && !b.isEmpty())
- {
- if(a.top()>b.top() || a.top()==b.top())temp.push(a.pop());
- if(a.top()==b.top()){temp.push(a.pop());b.pop();}
- else temp.push(b.pop());
- }
- if(!a.isEmpty())
- {
- while(!a.isEmpty())
- temp.push(a.pop());
- }
- if(!b.isEmpty())
- {
- while(!b.isEmpty())
- temp.push(a.pop());
- }
- return temp;
- }
- }
- ////////
- import unit4.collectionsLib.Stack;
- public class main2
- {
- public static void main2(String []args)
- {
- Stack <Integer>m = new Stack<Integer>();
- Stack <Integer>d = new Stack<Integer>();
- m.push(1);
- d.push(2);
- m.push(3);
- d.push(3);
- d.push(4);
- d.push(5);
- m.push(6);
- m.push(7);
- System.out.println(tar3.tar3(m,d));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement