SEMOGA BERMANFAAT: hapus antrian dengan Netbeans

Jumat, 07 Juni 2013

hapus antrian dengan Netbeans



Buat class queuee.java
package Queuee;
public class queuee {
private list listAntrian;
public queuee() {
listAntrian = new list( "queue" );
}                                                                              
public void enqueue( Object object ){
listAntrian.sisipDiAkhir( object );
}
public Object dequeue(){
return listAntrian.hapusDrDepan();
}
public boolean kosong(){
return listAntrian.kosong();
}
public void cetak(){listAntrian.cetak();}
  public static void main(String[] args) {
// TODO code application logic here
queuee q = new queuee();
q.enqueue( 8);
q.cetak();
q.enqueue( 16 );
q.cetak();
q.enqueue( 24 );
q.cetak();
q.enqueue( 32 );
q.cetak();
Object dtHapus = null;
while(!q.kosong()){
dtHapus = q.dequeue();
System.out.printf("%s dihapus \n",dtHapus );
q.cetak();
}
}
}

Buat class node.java
package Queuee;
public class node {
Object data;
node next;
node(Object object){this (object,null);}
node(Object object, node node){
data = object;
next = node;
}
Object getObject(){return data;}
node getNext() {return next;}
}


buat list.java
package Queuee;
public class list {
private node nodeAwal;
private node nodeAkhir;
private String nama;
public list(){ this( "list" ); }
public list( String namaList ){
nama = namaList;
nodeAwal = nodeAkhir = null;
}
public void sisipDiAwal( Object dt ){
if (kosong()) nodeAwal = nodeAkhir = new node( dt );
else nodeAwal = new node( dt, nodeAwal );
}
public void sisipDiAkhir( Object dt ){
if (kosong()) nodeAwal = nodeAkhir = new node( dt );
else nodeAkhir = nodeAkhir.next = new node( dt );
}
public Object hapusDrDepan(){
Object itemDihapus = null;
if (!kosong()) {
itemDihapus = nodeAwal.data;
if ( nodeAwal == nodeAkhir )
nodeAwal = nodeAkhir = null;
else nodeAwal = nodeAwal.next;
}
return itemDihapus;
}
public boolean kosong(){return nodeAwal == null;}
public void cetak(){
if ( kosong() ){
System.out.printf( "Kosong %s\n", nama );
return;
}
System.out.printf( "Isi %s adalah : ", nama );
node kini = nodeAwal;
while ( kini != null ){
System.out.printf( "%s ", kini.data );
kini = kini.next;
}
System.out.println( "\n" );
}
}

Tidak ada komentar:

Posting Komentar