ihsan1

queue+scanner1

May 15th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.76 KB | None | 0 0
  1. package semester2;
  2. import java.util.*;
  3. public class Kelompok {
  4.     Scanner scan;
  5.     Queue<Integer> queue;
  6.    
  7.     int n;
  8.    
  9.     void insert() {
  10.        
  11.         scan = new Scanner(System.in);
  12.         queue = new LinkedList<Integer>();
  13.        
  14.         System.out.println("Integer Queue - Insert & Delete");
  15.        
  16.         System.out.println("\nEnter 'n' value :");
  17.         n = scan.nextInt();
  18.        
  19.         System.out.println("Enter the elements");
  20.        
  21.         for(int i=0; i<n; i++) {
  22.            
  23.             queue.add(scan.nextInt());
  24.         }      
  25.     }
  26.    
  27.     void delete() {
  28.        
  29.         System.out.println("\nThe Queue");
  30.        
  31.         while(!queue.isEmpty()) {
  32.            
  33.             System.out.println(queue.poll());
  34.         }
  35.     }
  36. }
  37.  
  38. class MainClass {
  39.      public static void main(String[] args) {
  40.     Kelompok obj = new Kelompok();
  41.        
  42.         obj.insert();
  43.         obj.delete();;
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment