Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package semester2;
- import java.util.*;
- public class Kelompok {
- public static void main(String[] args) {
- int k=1;
- Stack<Integer> stack=new Stack<Integer>();
- Queue<Integer> queue= new LinkedList<Integer>();
- Scanner sc =new Scanner(System.in);
- do
- {
- int j=0,i,ent;
- System.out.println("Tekan 1 untuk Stack dan 2 untuk Queue");
- j=sc.nextInt();
- if(j==1)
- {
- System.out.println("Tekan 1 untuk Push dan 2 untuk Pop");
- i=sc.nextInt();
- if(i==1)
- {
- System.out.println("Masukan angka");
- ent =sc.nextInt();
- stack.push(ent);
- System.out.println(stack);
- }
- else
- {
- stack.pop();
- System.out.println(stack);
- }
- }
- else
- {
- System.out.println("Tekan 1 untuk Push dan 2 untuk Pop");
- i=sc.nextInt();
- if(i==1)
- {
- System.out.println("Masukan angka");
- ent =sc.nextInt();
- queue.add(ent);
- System.out.println(queue);
- }
- else
- {
- queue.remove();
- System.out.println(queue);
- }
- }
- System.out.println("press 1 to continue and 0 to exit");
- k=sc.nextInt();
- }while(k==1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment