Program Queue – Dequeue

Program Queue – Dequeue

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

Berikut SourcoCodenya:

<br />
import jeliot.io.*;</p>
<p>public class MyClass{<br />
       static int kepala,ekor,banyak_antrian;<br />
       static String antrian[] = new String [5];</p>
<p>       static void queue(){<br />
              kepala=ekor=-1;<br />
              banyak_antrian=0;<br />
       }</p>
<p>       static void enqueue(String data){<br />
              if(ekor==-1){<br />
                 kepala=ekor=0;<br />
                 antrian[ekor]=data;<br />
              }<br />
              else{<br />
                 ekor++;<br />
                 antrian[ekor]=data;<br />
              }<br />
       }                      </p>
<p>       static void dequeue(int a){<br />
              ekor--;<br />
              for(int i=0;i&amp;lt;=ekor;i++){<br />
                    antrian[i] = antrian[i+1];<br />
              }<br />
              antrian[ekor+1] =&quot;&quot;;<br />
       }       </p>
<p>       public static void main() {<br />
             queue();<br />
             int pil=0;</p>
<p>             while (pil != 3){<br />
                    System.out.println(&quot;1. Enqueue&quot;);<br />
                    System.out.println(&quot;2. Dequeue&quot;);<br />
                    System.out.println(&quot;3. Exit&quot;);<br />
                    System.out.print(&quot;Masukkan Pilihan: &quot;);pil=Input.readInt();<br />
                    if(pil==1){<br />
                      String isi = Input.readString();<br />
                      enqueue(isi);<br />
                      banyak_antrian ++;<br />
                    }<br />
                    else if(pil==2){<br />
                        int a=0;<br />
                        dequeue(a);<br />
                    }<br />
                    else{<br />
                        System.out.println(&quot;Pilihan tidak ada&quot;);<br />
                    }<br />
               }<br />
      }<br />
}<br />

Share