Here is a sample program Queue. Please be studied. :)
#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);
}
Search
Categories
Archives
-
▼
2011
(11)
-
▼
Desember
(11)
- Lyrik Yellow Card_Only One
- HTML Script in PHP
- Exercise Creating Functions for PHP
- Create_Database PHP
- Example Script PHP Connect to Database
- Program AVL Tree C++
- Ucapan Tahun Baru Shinen Omodetou Gozaimasu
- Source Code Program Bus Queue C++
- Basic Array Example Program
- sample program Queue
- What's Superskalar..???
-
▼
Desember
(11)