Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream.h>
- #include<conio.h>
- #include<stdio.h>
- struct STACK
- {
- int nilai[5];
- int top;
- };
- STACK tumpuk;
- void main()
- {
- clrscr();
- int pilih,baru,i;
- tumpuk.top=-1;
- do
- {
- cout<<endl;
- cout<<"1.Push"<<endl;
- cout<<"2.pop"<<endl;
- cout<<"3.Tampikan Data"<<endl;
- cout<<endl;
- cout<<"Masukan pilihan anda : ";
- cin>>pilih;
- switch(pilih)
- {
- case 1 :
- {
- if(tumpuk.top==5-1)
- {
- cout<<"Stack Penuh";
- getch();
- }
- else
- {
- cout<<"Push :";
- cin>>baru;
- tumpuk.top++;
- tumpuk.nilai[tumpuk.top]=baru;
- }
- break;
- }
- case 2 :
- {
- if(tumpuk.top==-1)
- {
- cout<<"Stack Kosong";
- getch();
- }
- else
- {
- cout<<"Pop :"<<tumpuk.nilai[tumpuk.top]<<endl;
- tumpuk.top--;
- getch();
- }
- break;
- }
- case 3 :
- {
- if(tumpuk.top==-1)
- {
- cout<<"Stack kosong "<<endl;
- getch();
- }
- else
- {
- cout<<"Data : ";
- for(i=0;i<=tumpuk.top;i++)
- {
- cout<<tumpuk.nilai[i]<<" ";
- }
- getch();
- }
- break;
- }
- default:
- {
- cout<<"maaf pilihan anda salah program akan berhenti"<<endl;
- }
- }
- }
- while(pilih>=1 && pilih<=3);
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement