document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include<iostream.h>
  2. #include<conio.h>
  3. #include<stdio.h>
  4.  
  5. struct STACK
  6. {
  7.     int value[6];  //Memberi nilai pada max stack
  8.            int top;
  9. };
  10.  
  11. STACK tumpuk;
  12.  
  13. void main()
  14. {
  15.     clrscr();
  16.    int pilih,baru,i;
  17.  
  18.    //inisialisasi awal
  19.  
  20.    tumpuk.top=-1;
  21.    do
  22.    {
  23.     clrscr();
  24.       cout<<"1.Push data"<<endl;
  25.       cout<<"2.Pop data"<<endl;
  26.       cout<<"3.Tampikan Value"<<endl;
  27.       cout<<endl;
  28.       cout<<"pilihan : ";
  29.       cin>>pilih;
  30.       switch(pilih)
  31.       {
  32.          case 1 :
  33.          {
  34.             if(tumpuk.top==6-1)
  35.             {
  36.                 cout<<"Stack sudah Penuh";
  37.                getch();
  38.             }
  39.             else
  40.             {
  41.                 cout<<"Push :";
  42.                cin>>baru;
  43.                tumpuk.top++;
  44.                tumpuk.value[tumpuk.top]=baru;
  45.             }
  46.             break;
  47.          }
  48.          case 2 :
  49.          {
  50.             if(tumpuk.top==-1)
  51.             {
  52.                 cout<<"Stack masih Kosong";
  53.                getch();
  54.             }
  55.             else
  56.             {
  57.                 cout<<"Pop = "<<tumpuk.value[tumpuk.top]<<endl;
  58.                tumpuk.top--;
  59.                getch();
  60.             }
  61.             break;
  62.          }
  63.          case 3 :
  64.          {
  65.             if(tumpuk.top==-1)
  66.             {
  67.                 cout<<"Stack masih kosong "<<endl;
  68.                 getch();
  69.             }
  70.             else
  71.             {
  72.                 cout<<"Value = ";
  73.                for(i=0;i<=tumpuk.top;i++)
  74.                {
  75.                 cout<<tumpuk.value[i]<<" ";
  76.                }
  77.                getch();
  78.             }
  79.             break;
  80.          }
  81.          default:
  82.          {
  83.             cout<<"maaf pilihan anda salah, program akan berhenti"<<endl;
  84.          }
  85.       }
  86.    }
  87.    while(pilih>=1 && pilih<=3);
  88.    getch();
  89. }
');