Struktur Data "Program Push , Pop , IsEmpty dan IsFull" pada C++
Program Push , Pop , IsEmpty dan IsFull
#include <iostream.h>
#include <conio.h>
int nilai[5];
int top, max;
int menu;
void push()
{
if (top==max)
{
cout<<"Stack Penuh...!";
}
else
{
top++;
cout<<"\nMasukan Data Ke Stack : ";
cin>>nilai[top];
}
getch();
}
void pop ()
{
if (top==-1)
{
cout<<"Stack Kosong...! ";
getch();
push();
}
else
{
cout<<"\nNilai Yang Di Pop : "<<nilai[top];
top--;
}
getch();
}
void print ()
{
if (top==-1)
{
cout<<"Stack Kosong....!";
}
else
{
for (int i=0;i<=top;i++)
{
cout<<nilai[i]<<" ";
}
}
getch();
}
void clear ()
{
top=-1;
cout<<"Proses Clear Sukses";
getch();
}
void main()
{
top = -1;
max = 4;
home:
clrscr();
cout<<" Pilih Salah Satu Menu Ini : "<<endl;
cout<<"============================="<<endl;
cout<<"1. Push"<<endl;
cout<<"2. Pop"<<endl;
cout<<"3. Print"<<endl;
cout<<"4, Clear"<<endl;
cout<<"5, Is Empty"<<endl;
cout<<"6, Is Full"<<endl;
cout<<"Pilihan Anda (1-6) : "<<endl;
cout<<"============================="<<endl;
cout<<"="<<endl;
cin>>menu;
cout<<"="<<endl;
switch(menu)
{
case 1:
push:
push ();
goto home;
break;
case 2:
pop ();
goto home;
break;
case 3:
print();
goto home;
break;
case 4:
clear ();
goto home;
break;
case 5:
if (top==-1)
{
cout<<"Stack Is Empty";
goto push;
}
else
{
cout<<"Terdapat Data Dalam Stack Yaitu : "; print();
goto home;
}
break;
case 6:
if (top==max)
{
cout<<"Stack Is Full";
pop ();
}
else
{
cout<<"Stack Masih Dapat Di Isi";
push();
goto home;
}
}
getch();
}
jazakumullah khairan
ReplyDeletetapi kenapa saya tidak bisa ya?
ReplyDelete