#include "iostream.h"
#include "conio.h"
#include "vector"
#define MAX 6
int head=0,tail=-1,data[MAX];
void insert(int x)
{
tail=(tail+1)%MAX;
data[tail]=x;
}
int del()
{
int t=0;
if(tail<=-1)
cout<<"\n\n Antrian Kosong.\n\n";
else
{
t=data[head];
if(head!=tail)
head=(head+1)%MAX;
else
{
head=0;
tail=-1;
}
}
return t;
}
void display()
{
int i;
if(tail<=-1)
cout<<"\n\n Antrian Kosong\n\n";
else
{
cout<<"\n\n Daftar Antrian :\n\n";
for(i=head;i!=tail;i=(i+1)%MAX)
cout< cout< }
}
void clear()
{
int i=0;
if(tail<=-1)
cout<<"\n\n Antrian Kosong\n\n";
else
for(i=head;i<=tail;i=(head+1)%MAX)
del();
if(i!=0)
cout<<"\n\n Antrian sudah dikosongkan\n\n";
}
void main()
{
int pilih,in,d;
clrscr();
do {
system("PAUSE");
clrscr();
cout<<"\n\n Menu:";
cout<<"\n 1. Menambah Antrian dibelakang (QUEUE)";
cout<<"\n 2. Mengurangi Antrian paling depan (DEQUEUE)";
cout<<"\n 3. Tampilkan Antrian";
cout<<"\n 4. Hapus Semua Antrian";
cout<<"\n 5. Keluar";
cout<<"\n\n Masukkan pilihan : ";
cin>>pilih;
switch(pilih)
{
case 1:
if(head==(tail+1)%MAX && tail>=MAX-1)
cout<<"\n\n Antrian sudah penuh\n\n";
else
{
cout<<"\n\n Tambahkan Antrian dibelakang : ";
cin>>in;
insert(in);
cout<<"\n";
system("PAUSE");
clrscr();
}
break;
case 2:
d=del();
if(d!=0)
cout<<"\n Kurangi Antrian paling depan : "<
clrscr();
break;
case 3:
display();
system("PAUSE");
clrscr();
break;
case 4:
clear();
system("PAUSE");
clrscr();
break;
case 5:
break;
default:clrscr();
cout<<"\n\n Pilihan Salah ! Silahkan ulangi kembali.\n\n";
}
}
while(pilih!=5);
}
Tidak ada komentar:
Posting Komentar