class NilaiMatKul{
String nim;
String nama;
double nilai;
NilaiMatKul(){
}
}
class Queue{
int first;
int last;
NilaiMatKul[] data = new NilaiMatKul[10];
Queue(){
for(int i=0;i<10;i++){
data[i] = new NilaiMatKul();
}
}
/*-----------------------------*/
void createEmpty(){
first = -1;
last = -1;
}
/*-----------------------------*/
boolean isEmpty(){
boolean hasil = false;
if(first == -1){
hasil = true;
}
return hasil;
}
/*-----------------------------*/
boolean isFull(){
boolean hasil = false;
if(last == 9){
hasil = true;
}
return hasil;
}
/*-----------------------------*/
void add(String nim, String nama, double nilai){
if(isEmpty() == true){
/*jika queue masih kosong*/
last = 0;
first = 0;
data[0].nim = nim;
data[0].nama = nama;
data[0].nilai = nilai;
}
else{
/*jika queue tidak kosong*/
if(isFull() != true){
last = last + 1;
data[last].nim = nim;
data[last].nama = nama;
data[last].nilai = nilai;
}
else{
System.out.println("queue penuh");
}
}
}
/*-----------------------------*/
void del(){
if(last == 0){
first = -1;
last = -1;
}
else{
/*menggeser elemen ke depan*/
int i;
for(i=(first + 1); i <= last; i++){
data[i-1].nim = data[i].nim;
data[i-1].nama = data[i].nama;
data[i-1].nilai = data[i].nilai;
}
last = last - 1;
}
}
/*-----------------------------*/
void printQueue(){
if(first != -1){
System.out.println("-------isi queue-------");
int i;
for(i = last;i >= first; i--){
System.out.println("=====================");
System.out.println("elemen ke :" + i);
System.out.println("nim : " + data[i].nim);
System.out.println("nama : " + data[i].nama);
System.out.println("nilai : " + data[i].nilai);
}
System.out.println("-----------------------");
}
else{
/*proses jika queue kosong*/
System.out.println("queue kosong");
}
}
/*-----------------------------*/
}
/*-----------------------------*/
class CobaQueueStatik{
public static void main(String[] args){
Queue Q = new Queue();
Q.createEmpty();
Q.printQueue();
System.out.println("================");
Q.add("13507701", "Nana", 64.75);
Q.add("13507702", "Rudi", 75.11);
Q.add("13507703", "Dea", 84.63);
Q.printQueue();
System.out.println("================");
Q.del();
Q.del();
Q.printQueue();
System.out.println("================");
}
}