Advertisement
Guest User

program stack

a guest
Oct 16th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.12 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5.  
  6. using namespace std;
  7.  
  8. struct coba
  9. {
  10.     char data[15][100];
  11.     int i;
  12. };
  13. coba stack;
  14.  
  15. void isi()
  16. {
  17.     stack.i++;
  18.     cout<<"Masukkan data = ";
  19.     cin>>stack.data[stack.i];
  20. }
  21.  
  22. void buang()
  23. {
  24.     if(stack.i>0)
  25.     {
  26.         cout<<"Data yang terambil : "<<stack.data[stack.i]<<endl;
  27.         stack.i--;
  28.     }
  29.     else
  30.     {
  31.         cout<<"Tidak ada yang terambil\n";
  32.     }
  33. }
  34.  
  35. void isfull(int n){
  36.     if(stack.i>=n)
  37.         cout<<"Tumpukan Penuh Gayn!!\n";
  38.     else
  39.     {
  40.         cout<<"Tumpukan masih ada Gayn... cukup\n";
  41.     }
  42. }
  43.  
  44. void isempty(int n){
  45.     if(stack.i<=n)
  46.         cout<<"Tumpukan kosong banget Gayn!!\n";
  47.     else
  48.         cout<<"Masih bisa diisi "<<n-stack.i<<" lagi\n";
  49. }
  50.  
  51. void muncul()
  52. {
  53.     if(stack.i>0)
  54.     {
  55.         for(int e=stack.i;e>=1;e--)
  56.             cout<<stack.data[e]<<endl;
  57.     }
  58.     else
  59.     {
  60.         cout<<"Tak ada data tersimpan\n";
  61.     }
  62. }
  63.  
  64. void hapus()
  65. {
  66.     cout<<"Data sudah dihapuskan\n";
  67.     stack.i=0;
  68. }
  69.  
  70. int main()
  71. {
  72.     int n,plh;
  73.     awal:
  74.     system("cls");
  75.     system("color 3f");
  76.     cout<<"\ncontoh program stack(Tumpukan)\n\n";
  77.     cout<<"maksimal tumpukan data : ";cin>>n;
  78.     stack.data[n];
  79.     stack.i=0;
  80.     pilihan:
  81.     system("cls");
  82.     system("color cf");
  83.     cout<<"\n1. push\n2. pop\n3. print\n4. clear\n5. cek full\n6. cek kosong\n7. quit\n\n";
  84.     cout<<"Pilih : ";cin>>plh;
  85.     cout<<endl;
  86.  
  87.     system("cls");
  88.     system("color df");
  89.     if(plh==1)
  90.     {
  91.         if(stack.i<n)
  92.         {
  93.             isi();
  94.         }
  95.         else
  96.         {
  97.             cout<<"tumpukan penuh\n";
  98.             getch();
  99.         }
  100.             goto pilihan;
  101.     }
  102.     else if(plh==2)
  103.     {buang();getch();goto pilihan;}
  104.     else if(plh==3)
  105.     {muncul();getch();goto pilihan;}
  106.     else if(plh==4)
  107.     {hapus();getch();goto pilihan;}
  108.     else if(plh==5)
  109.     {isfull(n);getch();goto pilihan;}
  110.     else if(plh==6)
  111.     {isempty(n);getch();goto pilihan;}
  112.     else if(plh==7)
  113.     {cout<<"Kita Keluar!!!\n";getch();}
  114.     getch();
  115.     return 0;
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement