single stack

May 30th, 2009 | Posted by
Contoh Single Stack

Contoh Single Stack

ciri2 single stack :

  1. kosong : top = -1
  2. penuh : top = n-1
  3. bisa diisi : top < n-1
  4. ada isinya : top > -1

kondisi awal :

top1 = -1;

algoritma dasar single stack :

  1. PUSH
    top = top + 1;
    s[top] = x;
  2. POP
    x = s[top];
    top = top - 1;

algoritma lengkap single stack :

  1. PUSH
    void PUSH(void){
      if(top > n -1 ){
          top = top + 1;
          s[top] = x
        }else{
          printf("stack penuh");
        }
    }
  2. POP
    void PUSH(void){
      if (top > -1){
           x = s[top];
           top = top - 1;
       }else{
           printf("stack kosong");
       }
    }

No related posts.

Tags:
No comments yet.
*