Home disini
widget by sy@ms

Latest Posts

Program Antrian

Nih ane kasih contoh program Antrian dengan menggunakan bahasa C++


#include <iostream.h>
#include <stdio.h>
#include <conio.h>
#define MAX 10

typedef struct {
int data[MAX];
int head;
int tail;
}Quene;
Quene antrian;
void Create()
{
antrian.head=antrian.tail=-1;
}

int IsEmpty()
{
if(antrian.tail==-1)
return 1;
else
return 0;
}

int IsFull()
{
if(antrian.tail==MAX-1)
return 1;
else
return 0;
}

void Equene(int data)
{
if(IsEmpty()==1)
{
antrian.head=antrian.tail=0;
antrian.data[antrian.tail]=data;
cout<<"Data "<<antrian.data[antrian.tail]<<" Masuk!!";
}
else if(IsFull()==0)
{
antrian.tail++;
antrian.data[antrian.tail]=data;
cout<<"Data "<<antrian.data[antrian.tail]<<" Masuk!!";
}
else if(IsFull()==1)
{
cout<<"Ruang Penuh !!"<<endl;
cout<<data<<" Ga Bisa Masuk!!";
}
}

void Dequene()
{
int i;
int e=antrian.data[antrian.head];
if(antrian.tail==-1)
{
cout<<"Ga Adsa Antrian... Data Kosong"<<endl;
}
else
{
for(i=antrian.head; i<=antrian.tail-1; i++)
{
antrian.data[i]=antrian.data[i+1];
}
antrian.tail--;
cout<<"Data yang keluar lebih dulu = "<<e<<endl;
}
}

void Clear()
{
antrian.head=antrian.tail=-1;
cout<<"Duh lega, Ruang Jadi Ga Sumpek...."<<endl;
cout<<"DAta Clear...";
}

void Tampil()
{
if(IsEmpty()==0)
{
cout<<"Data Dalam Antrian"<<endl;
cout<<"============================="<<endl;
cout<<endl;
for(int i=antrian.head; i<=antrian.tail; i++)
{
cout<<"| "<<antrian.data[i]<<" |";
}
}
else
cout<<"Ga Ada Antrian.... Data Kosng ";
}

void main()
{
int pil;
int data;
Create();
do
{
clrscr();
cout<<"Implementasi Antrian dengan struct"<<endl;
cout<<"=================================="<<endl;
cout<<endl;
cout<<"1. Equene(push)"<<endl;
cout<<"2. Dequene(pop)"<<endl;
cout<<"3. Print"<<endl;
cout<<"4. Clear"<<endl;
cout<<"5. Exit"<<endl;
cout<<"Pilihan Anda= ";cin>>pil;
switch(pil)
{
case 1: {
cout<<endl;
cout<<"Data= "; cin>>data;
Equene(data);
break;
}
case 2: {
cout<<endl;
Dequene();
break;
}
case 3: {
cout<<endl;
Tampil();
break;
}
case 4: {
cout<<endl;
Clear();
break;
}
}
getch();
}
while(pil!=5);
}




woke, moga berguna dan bermanfa.at bagi kita semua....




Salam senyum dariku untuk semuanya, tetaplah untuk bersemangat. Jangan lupa Comment atau isi buku tamu ya sob. Sedikit pemberitahuan untuk sobat yang ingin mengambil [Copy-Paste], Owner tidak melarang sobat untuk memperbanyak artikel namun Owner berharap sobat berlaku dengan bijak agar mencantumkan link active maupun yang tidak. Owner berharap partisipasinya ya sob.



0 komentar:

Jam Sekarang
Tanggal
Salam Sapa :
Status Blogging :

*ket. status : Terjadwal : Berarti yang punya blog tidak bisa berinternet [ More... ]





sy@ms
skyNET program


Join the conversation for skyNET program

 
 free web counter Counter Powered by  RedCounter

© 2011 || Copyright by sy@ms || Thanks for skyNET program All Reserved

Technology Blogs TopOfBlogs Top Blogs Internet Internet Blogs Phil Backlink Display Pagerank
Yahoo bot last visit powered by MyPagerank.Net
USA Backlinks Free Backlinks Service at USABacklinks.com! Auto Backlink Gratis Indonesia : Top Link Indo My Ping in TotalPing.com ping fast  my blog, website, or RSS feed for Free