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.  
  6. struct STACK
  7. {
  8.    int nilai[5];
  9.    int top;
  10. };
  11.  
  12. STACK tumpuk;
  13.  
  14. void main()
  15. {
  16.    clrscr();
  17.    int pilih,baru,i;
  18.  
  19.    tumpuk.top=-1;
  20.    do
  21.    {
  22.       cout<<endl;
  23.       cout<<"1.Push"<<endl;
  24.       cout<<"2.pop"<<endl;
  25.       cout<<"3.Tampikan Data"<<endl;
  26.       cout<<endl;
  27.       cout<<"Masukan pilihan anda : ";
  28.       cin>>pilih;
  29.       switch(pilih)
  30.       {
  31.          case 1 :
  32.          {
  33.             if(tumpuk.top==5-1)
  34.             {
  35.                 cout<<"Stack Penuh";
  36.                 getch();
  37.                 }
  38.             else
  39.             {
  40.                cout<<"Push :";
  41.                cin>>baru;
  42.                tumpuk.top++;
  43.                tumpuk.nilai[tumpuk.top]=baru;
  44.             }
  45.             break;
  46.          }
  47.          case 2 :
  48.          {
  49.            if(tumpuk.top==-1)
  50.             {
  51.                cout<<"Stack Kosong";
  52.                getch();
  53.             }
  54.             else
  55.             {
  56.                cout<<"Pop :"<<tumpuk.nilai[tumpuk.top]<<endl;
  57.                tumpuk.top--;
  58.                getch();
  59.             }
  60.             break;
  61.          }
  62.          case 3 :
  63.          {
  64.            if(tumpuk.top==-1)
  65.             {
  66.                cout<<"Stack kosong "<<endl;
  67.                getch();
  68.             }
  69.             else
  70.             {
  71.                cout<<"Data : ";
  72.                for(i=0;i<=tumpuk.top;i++)
  73.                {
  74.                 cout<<tumpuk.nilai[i]<<" ";
  75.                }
  76.                getch();
  77.             }
  78.             break;
  79.          }
  80.          default:
  81.          {
  82.             cout<<"maaf pilihan anda salah program akan berhenti"<<endl;
  83.          }
  84.       }
  85.    }
  86.    while(pilih>=1 && pilih<=3);
  87.    getch();
  88. }
');