coding:
#include<cstdlib>
#include<iostream>
#include<stdlib.h>
#define n 3
void INSERT(void);
void DELETE(void);
void CETAKLAYAR(void);
void Inisialisasi(void);
void RESET(void);
int PIL,F,R,counter,x;
char PILIHAN[1],HURUF;
char Q[n];
using namespace std;
int main()
{
Inisialisasi();
do
{
cout<<" ANIMASI QUEUE"<<endl;
cout<<" ============="<<endl;
cout<<"1. INSERT"<<endl;
cout<<"2. DELETE"<<endl;
cout<<"3. CETAK QUEUE"<<endl;
cout<<"4. QUIT"<<endl;
cout<<"PILIHAN"<<endl; cin>>PILIHAN;
PIL=atoi(PILIHAN);
switch(PIL)
{
case 1:
INSERT();
break;
case 2:
DELETE();
break;
case 3:
CETAKLAYAR();
break;
}
cout<<"TERIMA KASIH"<<endl;
system("PAUSE");
system("cls");
}
while (PIL<4);
return 0;
}
void INSERT(void)
{
if (counter<n)
{
cout<<endl<<"MASUKKAN 1 HURUF:";
cin>>HURUF;
Q[++R]=HURUF;
HURUF=Q[R];
Q[R]=x;
counter++;
system("PAUSE");
}
else
cout<<"Antrian Penuh"<<endl;
system("PAUSE");
}
void CETAKLAYAR(void)
{
if(F<R+1)
{
for(int i=F;i<=R;i++)
cout<<"Q["<<i<<"]="<<Q[i]<<endl;
system("PAUSE");
}
else
cout<<"QUEUE Kosong"<<endl;
system("PAUSE");
}
void DELETE(void)
{
if(counter>0)
{
x=Q[F];
F=(F+1)%n;
counter--;
HURUF=Q[F];
Q[F++]='\0';
cout<<"Data yang diambil:"<<HURUF<<endl;
if(F==n)
RESET();
system("PAUSE");
}
else
cout<<"Antrian Kosong"<<endl;
system("PAUSE");
}
void Inisialisasi(void)
{
F=0;
R=-1;
counter=0;
}
void RESET(void)
{
F=0;
R=-1;
counter=0;
}
|
Artikel Terbaru :