C++ Metode Pencarian Dengan Queue

Pemograman C++ dengan metode pencarian dengan queue

contoh program Queue :
//---------------------------------------------------------------------------

#include
#pragma hdrstop

//---------------------------------------------------------------------------

#pragma argsused
#include
#include
#include
#include

#define max 10

typedef struct
{
int head;
int tail;

char *t[max];
int a[max], s[max];

} queue;

queue pos;

void creat()
{
pos.head=pos.tail=-1;
}

iempty()
{
if(pos.tail==-1)
return 1;
else
return 0;
}

ifull()
{
if(pos.tail==max-1)
return 1;
else
return 0;
}

void enqueue(char *q, int w, int e)
{
if(iempty()==1)
{
pos.head=pos.tail=0;
pos.t[pos.tail]=q;
pos.a[pos.tail]=w;
pos.s[pos.tail]=e;
}

else if(ifull()==0)
{
pos.tail++;
pos.t[pos.tail]=q;
pos.a[pos.tail]=w;
pos.s[pos.tail]=e;
}

else if(ifull()==1)
{
cout<<"QUEUE PENUH";
}
}

dequeue()
{
if(iempty()==0)
{
int i;
char *z=pos.t[pos.tail];
int x=pos.a[pos.tail];
int c=pos.s[pos.tail];

for(i=pos.head; 1<=pos.tail-1; i++)
{
pos.t[i]=pos.t[i+1];
pos.a[i]=pos.a[i+1];
pos.s[i]=pos.s[i+1];
}

pos.tail--;
cout<<"DATA YANG DIHAPUS ADALAH : \n";
cout<<"Nama Barang : "<cout<<"Kode Barang : "<cout<<"Harga Barang : "<}

else if(iempty()==1)
{ cout<<"DATA EROR......QUEUE KOSONG"; }

return 1;
}

void clear()
{
pos.head=pos.tail=-1;
cout<<"QUEUE CLEAR";
}

void view()
{
if(iempty()==0)
{
cout<<"NO Nama Barang Kode Barang Harga Barang\n";

for(int i=pos.head; i<=pos.tail; i++)
{
cout<cout<cout<cout<}
}
else
{ cout<<"NO Nama Barang Kode Barang Harga Barang\n"; }
}

main()
{

int menu;
int acc, tpd;
char tip[30];

creat();

do{

clrscr();
cout<<"Nama : Bambang S\n";
cout<<"NIM  : 12012857\n";
cout<<"SMT  : III\n";
cout<<"\n";
cout<<"===========================\n";
cout<<" MENU PROGRAM QUEUE\n";
cout<<"===========================\n";
cout<<"1.ENQUEUE\n";
cout<<"2.DEQUEUE\n";
cout<<"3.CLEAR\n";
cout<<"4.VIEW\n";
cout<<"5.EXIT\n";
cout<<"===========================\n";
cout<<"PILIH MENU : "; cin>>menu;

switch(menu)
{
case 1:
cout<<"MASUKAN Nama Barang : "; cin>>tip;//gets(tip);
cout<<"MASUKAN Kode Barang : "; cin>>acc;
cout<<"MASUKAN Harga Barang : "; cin>>tpd;

enqueue(tip, acc, tpd);
break;

case 2:
dequeue();
break;

case 3:
clear();
break;

case 4:
view();
break;

case 5:
cout<<"exitttt.......bye...... :):D";
break;
}
getch();

}while(menu!=5);

}



Contoh Tampilan Program Setelah di Jalankan 

Share this article :
 

Post a Comment

Post Terupdate

Mr.Brex@Gmail.com . Powered by Blogger.

Post

 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. Komputer & Pemrograman - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger