Program Antrian(Queue) C++

This is the queue C + + program that I created when lab data structure
in this program print queue from the queue to enter the initial data ... and also delete the data queue

This program was

Berikut adalah contoh program Queue. Silahkan dipelajari. :)

#include<stdio.h>
#include<iostream.h>
#include<conio.h>
#define QSIZE 5
int front=0,rear=-1,q[QSIZE];
void masukkan(int x)
{
rear=(rear+1)%QSIZE;
q[rear]=x;
}


int hapus()
{
int t=0;
if(rear<=-1)
cout<<"\nAntrian kosong.\n\n";
else
{
t=q[front];
if(front!=rear)
front=(front+1)%QSIZE;
else
{
front=0;
rear=-1;
}
}
return t;
}
void tampilkan()
{
int i;
if(rear<=-1)
cout<<"\nAntrian kosong.\n\n";
else
{
cout<<"\nAntriannya adalah\n";
for(i=front;i!=rear;i=(i+1)%QSIZE)
cout<<q[i]<<" \t";
cout<<q[i]<<" \n";
}
}
void destroy()
{
int i=0;
if(rear<=-1)
cout<<"\nAntrian kosong.\n\n";
   else
for(i=front;i<=rear;i=(front+1)%QSIZE)
hapus();
if(i!=0)
cout<<"\nAntriannya sudah dibongkar.\n\n";
}
void main()
{
int ch,in,d;
clrscr();
do
{
cout<<"\nMain Menu\n\n";
cout<<"1.Masukkan\n";
cout<<"2.Hapus\n";
cout<<"3.Tampilkan\n";
cout<<"4.Destroy\n";
cout<<"5.Exit\n\n";
cout<<"Masukkan pilihan Anda:";
cin>>ch;
switch(ch)
{
case 1:clrscr();
          if(front==(rear+1)%QSIZE && rear>=QSIZE-1)
cout<<"\nAntriannya sudah penuh\n\n";
else
{
cout<<"\nMasukkan elemen yang akan di masukkan ke antrian:";
cin>>in;
masukkan(in);
clrscr();
}
break;
case 2:clrscr();
d=hapus();
if(d!=0)
cout<<"\nElement yang dihapus="<<d<<"\n\n";
break;
         case 3:clrscr();
tampilkan();
break;
case 4:clrscr();
destroy();
break;
case 5:break;
default:clrscr();
cout<<"\nEnter an appropriate choice.\n\n";
}

   }
while(ch!=5);

Posted in , , . Bookmark the permalink. RSS feed for this post.

One Response to Program Antrian(Queue) C++

Pages

Sandiah Notes Template Sandroid11.blogspot.com.