implementasi antrian
DESCRIPTION
Implementing Queue Using JAVATRANSCRIPT
![Page 1: IMPLEMENTASI ANTRIAN](https://reader036.vdocument.in/reader036/viewer/2022080222/563dbb43550346aa9aaba748/html5/thumbnails/1.jpg)
IMPLEMENTASI ANTRIAN (QUEUE)
1. CLASS ANTRIAN
package sd_mi_g;
public class Antrian { //Deklarasi Variabel private int jumlahMaks; private int atas; private int[] myAntrian; void lihatData() { System.out.println("ISI ANTRIAN"); for (int a = 0; a <= atas; a++) { System.out.print(myAntrian[a] + " "); } System.out.println(""); } public Antrian(int n) { jumlahMaks = n; atas = -1; myAntrian = new int[jumlahMaks]; } void tambah(int data) { if (! isFull()) { atas = atas + 1 ; // atas++; myAntrian[atas] = data; } else { System.out.println("Antrian Penuh"); } }
![Page 2: IMPLEMENTASI ANTRIAN](https://reader036.vdocument.in/reader036/viewer/2022080222/563dbb43550346aa9aaba748/html5/thumbnails/2.jpg)
boolean isFull() { boolean full; if(atas == (jumlahMaks - 1)) { full = true; } else { full = false; } return full; } void hapus() { if (! isEmpty()) { reOrder() ; atas = atas-1; // atas-- } else { System.out.println("Antrian Kosong"); } } void reOrder() { for(int a = 0; a < atas; a++) { myAntrian[a] = myAntrian[a+1]; } }
![Page 3: IMPLEMENTASI ANTRIAN](https://reader036.vdocument.in/reader036/viewer/2022080222/563dbb43550346aa9aaba748/html5/thumbnails/3.jpg)
boolean isEmpty() { boolean empty; if (atas == -1) { empty = true; } else { empty = false; } return empty; }}
2. CLASS UJI ANTRIAN
package sd_mi_g;
public class UjiAntrian { public static void main (String[] args) { Antrian uji = new Antrian(6); uji.tambah(8); uji.tambah(10); uji.tambah(20); uji.tambah(30); uji.tambah(40); uji.tambah(50); uji.tambah(60); uji.lihatData(); uji.hapus(); uji.hapus(); uji.hapus(); uji.hapus(); uji.hapus(); uji.hapus(); uji.hapus(); uji.lihatData(); }}