Advertisement
safriansah

queue

Aug 3rd, 2018
15,330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.51 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class bank{
  3.     int id;
  4.     String nama,perlu;
  5.     bank next;
  6.     static Scanner in=new Scanner(System.in);
  7.     static Scanner str=new Scanner(System.in);
  8.     public void input(){
  9.         System.out.print("Masukkan id        : ");
  10.         id=in.nextInt();
  11.         System.out.print("Masukkan nama      : ");
  12.         nama=str.nextLine();
  13.         System.out.print("Masukkan keperluan : ");
  14.         perlu=str.nextLine();
  15.         next=null;
  16.     }
  17.     public void read(){
  18.         System.out.println("|| "+id+" \t|| "+nama+" \t|| "+perlu+" \t||");
  19.     }
  20.     public static void main(String[] args){
  21.         int menu=0;
  22.         linked que=new linked();
  23.         while(menu!=4){
  24.             System.out.print("1.Enqueue\n2.Dequeue\n3.View\n4.Exit\n : ");
  25.             menu=in.nextInt();
  26.             if(menu==1)que.enque();
  27.             else if(menu==2)que.deque();
  28.             else if(menu==3)que.view();
  29.             else if(menu==4)System.out.println("- keluar -");
  30.             else System.out.println("- Salah -");
  31.             System.out.println("");
  32.         }
  33.     }
  34. }
  35. class linked{
  36.     bank head,tail;
  37.     public linked(){
  38.         head=null;
  39.         tail=null;
  40.     }
  41.     public void enque(){
  42.         bank baru=new bank();
  43.         baru.input();
  44.         if(head==null)head=baru;
  45.         else tail.next=baru;
  46.         tail=baru;
  47.     }
  48.     public void deque(){
  49.         if(head==null)System.out.println("- Kosong -");
  50.         else{
  51.             System.out.println("Keluar Data Dengan Id : "+head.id);
  52.             head=head.next;
  53.         }
  54.     }
  55.     public void view(){
  56.         if(head==null)System.out.println("- Kosong -");
  57.         else{
  58.             System.out.println("|| Id \t|| Nama \t|| Keperluan \t||");
  59.             for(bank a=head; a!=null; a=a.next) a.read();
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement