Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <stdlib.h>
- #include <string.h>
- using namespace std;
- struct coba
- {
- char data[15][100];
- int i;
- };
- coba stack;
- void isi()
- {
- stack.i++;
- cout<<"Masukkan data = ";
- cin>>stack.data[stack.i];
- }
- void buang()
- {
- if(stack.i>0)
- {
- cout<<"Data yang terambil : "<<stack.data[stack.i]<<endl;
- stack.i--;
- }
- else
- {
- cout<<"Tidak ada yang terambil\n";
- }
- }
- void isfull(int n){
- if(stack.i>=n)
- cout<<"Tumpukan Penuh Gayn!!\n";
- else
- {
- cout<<"Tumpukan masih ada Gayn... cukup\n";
- }
- }
- void isempty(int n){
- if(stack.i<=n)
- cout<<"Tumpukan kosong banget Gayn!!\n";
- else
- cout<<"Masih bisa diisi "<<n-stack.i<<" lagi\n";
- }
- void muncul()
- {
- if(stack.i>0)
- {
- for(int e=stack.i;e>=1;e--)
- cout<<stack.data[e]<<endl;
- }
- else
- {
- cout<<"Tak ada data tersimpan\n";
- }
- }
- void hapus()
- {
- cout<<"Data sudah dihapuskan\n";
- stack.i=0;
- }
- int main()
- {
- int n,plh;
- awal:
- system("cls");
- system("color 3f");
- cout<<"\ncontoh program stack(Tumpukan)\n\n";
- cout<<"maksimal tumpukan data : ";cin>>n;
- stack.data[n];
- stack.i=0;
- pilihan:
- system("cls");
- system("color cf");
- cout<<"\n1. push\n2. pop\n3. print\n4. clear\n5. cek full\n6. cek kosong\n7. quit\n\n";
- cout<<"Pilih : ";cin>>plh;
- cout<<endl;
- system("cls");
- system("color df");
- if(plh==1)
- {
- if(stack.i<n)
- {
- isi();
- }
- else
- {
- cout<<"tumpukan penuh\n";
- getch();
- }
- goto pilihan;
- }
- else if(plh==2)
- {buang();getch();goto pilihan;}
- else if(plh==3)
- {muncul();getch();goto pilihan;}
- else if(plh==4)
- {hapus();getch();goto pilihan;}
- else if(plh==5)
- {isfull(n);getch();goto pilihan;}
- else if(plh==6)
- {isempty(n);getch();goto pilihan;}
- else if(plh==7)
- {cout<<"Kita Keluar!!!\n";getch();}
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement