double ended queue

Contoh Double Ended Queue

Contoh Double Ended Queue

ciri2 double ended queue :

  1. kosong : L = R + 1
  2. penuh kanan : R = n – 1
  3. penuh kiri : L = 0
  4. penuh kanan dan kiri : R = n – 1 && L = 0
  5. bisa diisi dari kanan : R < n
  6. bisa diisi dari kiri : L > 0
  7. ada isinya : L < R + 1

kondisi awal :

L = 0;
R = -1;

algoritma dasar double ended queue :

  1. INSERT KANAN
    R = R + 1;
    Q[R] = X;
  2. INSERT KIRI
    L = L - 1;
    Q[L] = X;
  3. DELETE KANAN
    X = Q[R];
    R = R - 1;
  4. DELETE KIRI
    X = Q[L];
    L = L + 1;


algoritma lengkap double ended queue :

  1. INSERT KANAN
    void INSERT_KANAN(void){
      if(R < n-1){
         R  =  R + 1;
         Q[R]  =  X;
      }else{
         printf("antrian penuh kanan");
      }
    }
  2. INSERT KIRI
    void INSERT_KIRI(void){
      if( L > 0){
          L = L - 1; 
          Q[L]  =  X;
      }else{
          printf("antrian penuh kiri");
      }
    }
  3. DELETE KANAN
    void DELETE_KANAN(void){
      if(L < R+1){
         X  =  Q[R];
         R   =   R - 1;
      }else{
        printf("antrian kosong");
      }
    }
  4. DELETE KIRI
    void DELETE_KIRI(void){
      if(L < R+1){
         X = Q[L];
         L = L + 1;
      }else{
         printf("antrian kosong");
      }
    }

Bookmarks:
  • Facebook
  • Google Bookmarks
  • Digg
  • LinkedIn
  • Twitter

Related posts:

  1. circular queue ciri2 circular queue : kosong : counter = 0 penuh...
  2. double stack ciri2 double stack : stack 1 kosong : top1 =...
  3. single stack ciri2 single stack : kosong : top = -1 penuh...
  4. linked list hitung jumlah simpul : Q = FIRST; Jum = 1;...

Related posts brought to you by Yet Another Related Posts Plugin.

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre user="" computer="" escaped="">