Strutur Data Queue C++.cpp

  • Uploaded by: Abdur Rohman M
  • 0
  • 0
  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Strutur Data Queue C++.cpp as PDF for free.

More details

  • Words: 228
  • Pages: 5
BAB I queue.cpp #include "queue01.h" #include 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

Related Documents

Queue Data Structure
June 2020 3
Queue
December 2019 34
Queue
November 2019 15
A Queue
October 2019 24

More Documents from "Imam Ciptarjo"