Program Queue – Dequeue

Program Queue – Dequeue

Hosting Unlimited Indonesia

Bagi teman2 yang butuh SourcoCode Program Dequeue dengan bahasa Java disini ada tapi disini memakai Jeliot.

Berikut SourcoCodenya:

import jeliot.io.*;

public class MyClass{
       static int kepala,ekor,banyak_antrian;
       static String antrian[] = new String [5];

       static void queue(){
              kepala=ekor=-1;
              banyak_antrian=0;
       }
       
       static void enqueue(String data){
              if(ekor==-1){
                 kepala=ekor=0;
                 antrian[ekor]=data;
              }
              else{
                 ekor++;
                 antrian[ekor]=data;
              }
       }                      

       static void dequeue(int a){
              ekor--;
              for(int i=0;i<=ekor;i++){
                    antrian[i] = antrian[i+1];
              }
              antrian[ekor+1] ="";
       }       

       public static void main() {
             queue();
             int pil=0;

             while (pil != 3){
                    System.out.println("1. Enqueue");
                    System.out.println("2. Dequeue");
                    System.out.println("3. Exit");
                    System.out.print("Masukkan Pilihan: ");pil=Input.readInt();
                    if(pil==1){
                      String isi = Input.readString();
                      enqueue(isi);
                      banyak_antrian ++;
                    }
                    else if(pil==2){
                        int a=0;
                        dequeue(a);
                    }
                    else{
                        System.out.println("Pilihan tidak ada");
                    }
               }
      }
}
Hosting Unlimited Indonesia
Share