Contoh Program Antrian
Source Code C++:
#include <iostream.h>
#include <conio.h>
int main()
{
int cek=0, data[20], x, hapus;
char pil;
do {
cout<<"1. Tambah Antrian"<<endl;
cout<<"2. Hapus Antrian"<<endl;
cout<<"3. Lihat Antrian"<<endl;
cout<<"4. Keluar"<<endl;
cout<<endl;
cout<<"Silahkan masukkan pilihan anda = ";
pil=getche();
cout<<endl;
if(pil!='1' && pil !='2' && pil !='3' && pil!='4' )
cout<<"Anda salah mengetikkan inputan";
else
{
if(pil=='1') //PUSH
{
if(cek==20)
cout<<"Antrian Penuh";
else
{
cout<<"Masukkan nilai = ";
cin>>x;
data[cek]=x;
cek++;
}
}
else
{
if(pil=='2') //POP
{
if(cek==0)
cout<<"Antrian kosong";
else
{
hapus=data[0];
for(int v=0;v<cek;v++)
data[v]=data[v+1];
data[cek-1]=NULL;
cek--;
cout<<"Data dengan nilai "<<hapus<<" terhapus";
}
getch();
}
else
{
if(pil=='3') //CEK DATA
{
if(cek==0)
cout<<"Antrian Kosong";
else
{
cout<<endl;
for(int z=0;z<cek;z++)
{
cout<<" | ";
cout<<" "<<data[z];
cout<<" | ";
}
}
getch();
return 0;
}
}
}
}
}while(pil!='4');
}
#include <iostream.h>
#include <conio.h>
int main()
{
int cek=0, data[20], x, hapus;
char pil;
do {
cout<<"1. Tambah Antrian"<<endl;
cout<<"2. Hapus Antrian"<<endl;
cout<<"3. Lihat Antrian"<<endl;
cout<<"4. Keluar"<<endl;
cout<<endl;
cout<<"Silahkan masukkan pilihan anda = ";
pil=getche();
cout<<endl;
if(pil!='1' && pil !='2' && pil !='3' && pil!='4' )
cout<<"Anda salah mengetikkan inputan";
else
{
if(pil=='1') //PUSH
{
if(cek==20)
cout<<"Antrian Penuh";
else
{
cout<<"Masukkan nilai = ";
cin>>x;
data[cek]=x;
cek++;
}
}
else
{
if(pil=='2') //POP
{
if(cek==0)
cout<<"Antrian kosong";
else
{
hapus=data[0];
for(int v=0;v<cek;v++)
data[v]=data[v+1];
data[cek-1]=NULL;
cek--;
cout<<"Data dengan nilai "<<hapus<<" terhapus";
}
getch();
}
else
{
if(pil=='3') //CEK DATA
{
if(cek==0)
cout<<"Antrian Kosong";
else
{
cout<<endl;
for(int z=0;z<cek;z++)
{
cout<<" | ";
cout<<" "<<data[z];
cout<<" | ";
}
}
getch();
return 0;
}
}
}
}
}while(pil!='4');
}
0 komentar:
Post a Comment