P. 1
Strutur Data Queue c++.cpp

Strutur Data Queue c++.cpp

|Views: 2,451|Likes:
Published by Abdur Rohman M
contoh program struktur data queue.cpp
contoh program struktur data queue.cpp

More info:

Published by: Abdur Rohman M on Nov 15, 2009
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

06/29/2013

pdf

text

original

BAB I queue.

cpp
#include "queue01.h" #include <iostream.h> int array [QUEUE_SIZE]; int awal=-1; int akhir=-1; int is_empty(){ if ((awal==-1)&&(akhir==-1)) return 1; else return 0; } int is_full(){ if(akhir==QUEUE_SIZE-1) return 1; else return 0; } void enqueue_item(int item){ if(!is_full()){ if(awal==-1){ awal++; akhir++; } else akhir++; array[akhir]=item; } else cout<<"full"; } char dequeue_item(void){ if(!is_empty()){ awal++; cout<<"\n first out"<<endl; } else cout<<"empty"; } void print_item(){ if(!is_empty()){ for(int i =awal;i<=akhir;i++) cout<<array[i];

} else cout<<"empty"; } int main(){ int item; cout<<"BAB I, queue."<<endl; int pilih; do{ cout<<"\nmenu"<<endl; cout<<"1.add queue"<<endl; cout<<"2.delete queue"<<endl; cout<<"3.print"<<endl; cout<<"4.exit"<<endl; cin>>pilih; switch (pilih){ case 1: cout<<"insert new cin>>item;enqueue_item(item); break; case 2: dequeue_item(); break; case 3: cout<<"\nQueue contains"<<endl; break; case 4: system("cls"); cout<<"\tBye"; } }while(pilih<=3); return 0; }

data=";

print_item();

queue01.h
/* Praktikum : QUEUE (antrian) dengan menggunakan array /* Praktikan mendefinisikan suatu variable global yg bisa dimodifikasi dari dalam suatu fungsi */ /****************************************/ /* PROTOTYPE */ #define QUEUE_SIZE 5 /* Memeriksa apakah suatu Queue kosong? */ extern int is_empty(void); /* Memeriksa apakah suatu Queue penuh? */ extern int is_full(void); /* Menambahkan suatu item ke dalam queue */ /* Kemungkinan error, karena ukuran array sudah penuh */ extern void enqueue_item(char item); /* Mengambil suatu item dari dalam queue */ extern char dequeue_item(void); /* Mencetak isi queue (dari yang pertama masuk), jika ada extern void print_item(void); */

*/

PrintScreen Program

Menu Program

Delete empty Queue

Insert Item

Print

Delete queue

Insert after delete

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->