Link.java
public class Link {
private Node Front;
private Node Rear;
public Link(){
Front = null;
Rear = null;
}
public boolean isEmpty(){
return (Front==null);
}
public void enqueue(int a, String b, String c){
Node newNode = new Node(a,b,c);
if( isEmpty() )
Front = newNode;
else
Rear.next = newNode;
Rear = newNode;
}
public void dequeue(){
Front = Front.next;
}
public void printList(){
System.out.println("-----------------------------------------");
System.out.println("| NPM | NAMA | JURUSAN |" );
System.out.println("-----------------------------------------");
Node pertama = Front;
int count=1;
while(pertama != null){
System.out.print(count+". ");
count++;
pertama.printNode();
pertama = pertama.next;
}
}
}
==================================================================
Node.java
public class Node {
public int npm;
public String Nama;
public String Jurusan;
public Node next;
public Node(int a, String b, String c){
this.npm = a;
this.Nama = b;
this.Jurusan = c;
}
public void printNode(){
System.out.println(npm+" "+Nama+" "+Jurusan);
}
}
==================================================================
QueueApp.java
public class QueueApp {
public static void main(String[]args){
int menu;
Link list = new Link();
do{
menu = Integer.parseInt(JOptionPane.showInputDialog("Program Queue"
+ "\n1. Insert"
+ "\n2. Delete"
+ "\n3. Print"
+ "\n4. Exit"));
try{
switch(menu){
case 1:
int a = Integer.parseInt(JOptionPane.showInputDialog("Masukkan NPM"));
String b = JOptionPane.showInputDialog("Masukkan Nama");
String c = JOptionPane.showInputDialog("Masukkan Jurusan");
list.enqueue(a,b,c);
JOptionPane.showMessageDialog(null,"Data berhasil disimpan");
break;
case 2:
JOptionPane.showMessageDialog(null,"Data berhasil di hapus");
list.dequeue();
break;
case 3:
list.printList();
break;
case 4:
JOptionPane.showMessageDialog(null,"Terima Kasih");
break;
default:
break;
}
}catch(Exception e){
JOptionPane.showMessageDialog(null,"input anda salah");
}
}while(menu!=4);
}
}
Tidak ada komentar:
Posting Komentar