double stack

Contoh Double Stack

Contoh Double Stack

ciri2 double stack :

  1. stack 1 kosong : top1 = -1
  2. stack 2 kosong : top2 = n
  3. stack penuh (stack 1 dan stack 2 tidak bisa diisi) : top2 – top1 = 1
  4. stack bisa diisi (stack 1 dan stack 2 tidak bisa diisi) : top2 – top1 > 1
  5. stack 1 ada isinya : top1 > -1
  6. stack 2 ada isinya : top2 < n

kondisi awal :

top1 = -1;
top2 = n;

algoritma dasar double stack :

  1. PUSH stack 1
    top1 = top1 + 1;
    s[top1] = x;
  2. POP stack 1
    x = s[top1];
    top1 = top1 - 1;
  3. PUSH stack 2
    top2 = top2 - 1;
    s[top2] = x;
  4. POP stack 2
    x = s[top2];
    top2 = top2 + 1;

algoritma lengkap double stack :

  1. PUSH stack 1
    void PUSH1(void){
       if(top2 - top1 &gt; 1){
           top1  =  top1 + 1;
           s[top1] = x;
       }else{
           printf( "stack penuh");
       }
    }
  2. POP stack 1
    void POP1(void){
       if(top1 &gt; -1){
           x  =  s[top1];
           top1 = top1 - 1;
       }else{
           printf( "stack 1 kosong");
       }
    }
  3. PUSH stack 2
    void PUSH2(void){
       if(top2 - top1 &gt; 1){
           top2  =  top2 + 1;
           s[top2] = x;
       }else{
           printf( "stack penuh");
       }
    }
  4. POP stack 2
    void POP2(void){
       if(top2 &lt; n){
           x  =  s[top2];
           top2 = top2 + 1;
       }else{
           printf( "stack 2 kosong");
       }
    }

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

Related posts:

  1. single stack ciri2 single stack : kosong : top = -1 penuh...
  2. double ended queue ciri2 double ended queue : kosong : L = R...
  3. circular queue ciri2 circular queue : kosong : counter = 0 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="">