StackApp.java
public class StackApp {
public static void main(String[]args){
int mn;
Procedur list = new Procedur();
do{
mn = Integer.parseInt(JOptionPane.showInputDialog("1. Insert Mahasiswa\n2. Delete\n3. View\n4. Keluar"));
try{
switch(mn){
case 1:
String p = JOptionPane.showInputDialog("Masukkan npm");
String n = JOptionPane.showInputDialog("Masukkan nama");
String j = JOptionPane.showInputDialog("Masukkan jurusan");
list.push(p, n, j);
break;
case 2:
list.pop();
break;
case 3:
list.CetakLinklist();
break;
case 4:
System.exit(0);
break;
default:
break;
}
}catch(Exception e){
JOptionPane.showMessageDialog(null,"input salah");
}
}while(mn!=4);
}
}
//==================================================
Mahasiswa.java
public class Mahasiswa {
public String npm;
public String nama;
public String jurusan;
public Mahasiswa next;
public Mahasiswa(String p, String n, String j){
this.npm = p;
this.nama = n;
this.jurusan = j;
}
public void printNode(){
System.out.println(npm+" "+nama+" "+jurusan);
}
}
//===================================================
Procedur.java
public class Procedur {
private Mahasiswa F;
private Mahasiswa L;
private int bts;
public Procedur(){
F = null;
L = null;
bts = 0;
}
public void push(String p, String n, String j){
Mahasiswa newNode = new Mahasiswa(p,n,j);
newNode.next = F;
F = newNode;
bts++;
}
public void pop(){
F = F.next;
bts--;
}
public boolean Kosong(){
return (F==null);
}
public void CetakLinklist(){
System.out.println("---------------");
System.out.println("| cetak |" );
System.out.println("---------------");
Mahasiswa per = F;
int no=bts;
while(per != null){
System.out.print(no+". ");
no--;
per.printNode();
per = per.next;
}
}
}
Tidak ada komentar:
Posting Komentar