Skip to main content

stack Animasi

// PROGRAN ANIMASI STACK DALAM C++
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>

int atas,i;
char pil,temp,rr;
char stack[20];
void delay();

void pushangka(){
       for(i=0;i<=20; i++){
           gotoxy(24+i,7);cout<<" ";
           gotoxy(25+i,7); cout<<temp; delay();
         }
       for(i=1;i<=(15-atas);i++){
           delay();
           gotoxy(40,6+i); cout<<" ";
           gotoxy(40,7+i); cout<<temp;
         }
    }

void popangka(char temp){
       for(i=1;i<=(15-atas);i++){
           delay();
           gotoxy(40,22-i-atas); cout<<" ";
           gotoxy(40,21-i-atas); cout<<temp;
         }
        for(i=1;i<=19;i++){
           delay();
           gotoxy(38+i,7); cout<<" ";
           gotoxy(39+i,7); cout<<temp; delay();
         }
        gotoxy(58,7);cout<<" ";
    }

void push(char rr){
       atas=atas+1;
       stack[atas]=rr;
       pushangka();
     }
void pop(char rr){
       if(atas !=0) {
           rr=stack[atas]; popangka(rr);
           atas=atas-1;
          }
      else{
           gotoxy(1,7); cout<<"STACK TELAH KOSONG"<<endl;
           gotoxy(1,7);
         }
      }

void main(){
        clrscr();
        cout<<"STACK  ANIMASI"<<endl;
        cout<<"1.Tambah Data (Push)"<<endl;
        cout<<"2.Ambil Data (Pop)"<<endl;
        cout<<"3.Hapus Data (clear)"<<endl;
        cout<<"4.exit"<<endl;
        //cout<<"pilih [1/2/3/4] ="<<endl;
        gotoxy(59,6); cout<<"=";
        gotoxy(59,8); cout<<"=";
        gotoxy(37,9); cout<<"||   ||";
        for(i=1;i<=11;i++)
      {
        gotoxy(38,10+i);
        if(i==11)
        cout<<"|___|";
        else
        cout<<"|   |";
  }
  atas=0;
  do {
        input:
        gotoxy(1,5);
        cout<<"masukkan pilihan anda[1/2/3/4] : ";
        pil=getche();
        if(int(pil)==27 || pil=='3')
        break;
        else if(pil=='1'){
              if(atas != 10) {
                    gotoxy(1,7); cout<<"masukkan angka : ";
                    cin>>temp;
                    push(temp);
                    gotoxy(1,7); cout<<"                      ";
                  }
              else {
                    gotoxy(1,7); cout<<"stack overload";
                    getch();
                    gotoxy(1,7); cout<<"     ";
                  }
            }
        else if(pil=='2')
        pop(temp);
        else
        goto input;
        }
  while(1);

        getch();
    }

 void delay(){
        for(int y=1;y<80;y++)
        for(int x=1;x<80;x++)
        for(int p=1;p<80;p++)
        cout<<"";
 }

Comments