Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include<iostream.h>
  2. #include<stdlib.h>
  3. #include<conio.h>
  4.  
  5. //Created by Krisna Anggara
  6.  
  7. #define n 10
  8. int S[n],top1,top2,x,i;
  9. char jawab,jawab1;
  10.  
  11. void awal()
  12. {
  13.     top1=-1;top2=n;
  14. }
  15.  
  16. void push1()
  17. {
  18.     if (top2-top1>1)
  19.     {
  20.         top1=top1++;
  21.         S[top1]=x;
  22.     }
  23.     else
  24.         cout<<"Stack penuh";
  25. }
  26.  
  27. void push2()
  28. {
  29.     if (top2-top1>1)
  30.     {
  31.         top2=top2--;
  32.         S[top2]=x;
  33.     }
  34.     else
  35.         cout<<"Stack penuh";
  36.  
  37. }
  38.  
  39. void pop1()
  40. {
  41.      if (top1>-1)
  42.      {
  43.         x=S[top1];
  44.         top1=top1--;
  45.       cout<<"Isi Stack Adalah : "<<S[top1];
  46.      }
  47.      else
  48.         cout<<"Stack kosong";
  49.  
  50. }
  51.  
  52.  
  53. void pop2()
  54. {
  55.      if (top2<n)
  56.      {
  57.         x=S[top2];
  58.         top2++;
  59.       cout<<"Isi Stack Adalah : "<<S[top2];
  60.      }
  61.      else
  62.         cout<<"Stack kosong";
  63.  
  64. }
  65.  
  66. void main()
  67. {
  68.     int pilih;
  69.  
  70.     awal();
  71.     menu :
  72.     clrscr();
  73.     cout<<"1.PUSH1"<<endl;
  74.     cout<<"2.PUSH2"<<endl;
  75.     cout<<"3.POP1"<<endl;
  76.     cout<<"4.POP2"<<endl;
  77.     cout<<"5.EXIT"<<endl;
  78.     cout<<"Inputkan pilihan anda :";
  79.     cin>>pilih;
  80.  
  81.     switch (pilih)
  82.     {
  83.         case 1 :
  84.             clrscr();
  85.          do
  86.          {
  87.          cout<<"Inputkan data :";
  88.             cin>>x;
  89.             push1();
  90.          cout<<"Apakah Anda Ingin Memasukan Data Lagi? [Y/T] :";cin>>jawab;
  91.          }
  92.          while ((jawab=='Y')||(jawab=='y'));
  93.           cout<<"Isi Stack Sebelum POP :"<<endl;
  94.           for(i=0;i<=top1;i++)
  95.             {
  96.             cout<<"|";
  97.             cout<<S[i]<<"| ";
  98.             }
  99.            cout<<endl;
  100.            cout<<"Apakah anda ingin kembalik ke menu? [Y/T] :";cin>>jawab1;
  101.            if ((jawab1=='Y')||(jawab1=='y'))
  102.             {
  103.             goto menu;
  104.             } else
  105.           break;
  106.  
  107.         case 2 :
  108.             clrscr();
  109.          do
  110.          {
  111.          cout<<"Inputkan data :";
  112.             cin>>x;
  113.             push2();
  114.          cout<<"Apakah Anda Ingin Memasukan Data Lagi? [Y/T] :";cin>>jawab;
  115.          }
  116.          while ((jawab=='Y')||(jawab=='y'));
  117.           cout<<"Isi Stack Sebelum POP :"<<endl;
  118.           for(i=n-1;i>=top2;i--)
  119.             {
  120.             cout<<"|";
  121.             cout<<S[i]<<"| ";
  122.             }
  123.            cout<<endl;
  124.            cout<<"Apakah anda ingin kembalik ke menu? [Y/T] :";cin>>jawab1;
  125.            if ((jawab1=='Y')||(jawab1=='y'))
  126.             {
  127.             goto menu;
  128.             } else
  129.           break;
  130.  
  131.         case 3 :
  132.             pop1();
  133.             break;
  134.  
  135.         case 4 :
  136.             pop2();
  137.             break;
  138.  
  139.         case 5 :
  140.             exit;
  141.  
  142.     }
  143.     getch();
  144.  
  145. }