Source code:
#include<iostream> #include<cstdlib> #include<conio.h> #define n 3 void INSERT(void); void DELETE(void); void CETAKLAYAR(void); void inisialisasi(void); int PIL,F,R,COUNTER; char PILIHAN[1],HURUF; char Q[n]; using namespace std; int main() { inisialisasi(); do { cout<<" CIRCULAR QUEUE "<<endl; cout<<"_____________________________________________________________________"<<endl; cout<<" PROGRAM ANIMASI QUEUE "<<endl; cout<<"====================================================================="<<endl; cout<<" 1.INSERT "<<endl; cout<<" 2.DELETE "<<endl; cout<<" 3.CETAK ANTRIAN "<<endl; cout<<" 4.KELUAR "<<endl; cout<<" * CATATAN : BATAS INPUT = 3 HURUF "<<endl; cout<<"_____________________________________________________________________"<<endl; cout<<endl; cout<<" SILAHKAN MASUKKAN PILIHAN : ";cin>>PILIHAN; PIL=atoi(PILIHAN); switch(PIL) { case 1: INSERT(); break; case 2: DELETE(); break; case 3: CETAKLAYAR(); break; default : cout<<"TERIMA KASIH"<<endl; break; } cout<<"Press any key to continue"<<endl; getch(); system("cls"); } while (PIL<4); return 0; } void INSERT(void) { if(COUNTER<n) { cout<<endl<<"Masukkan 1 huruf : "; cin>>HURUF; R = (R + 1) % n; Q[R] = HURUF; COUNTER++; } else cout<<"Antrian Penuh!"<<endl; } void CETAKLAYAR(void) { if(COUNTER>0) { for(int k = 0; k < COUNTER; k++) { int i = (F+k) % n; cout << "Q["<<k<<"]="<<Q[i] << endl; } } else cout<<"Queue kosong!"<<endl; } void DELETE(void) { if(COUNTER>0) { HURUF=Q[F]; F = (F + 1) %n; COUNTER--; cout<<"Data yang di ambil :"<<HURUF<<endl; } else cout<<"Antrian Kosong!"<<endl; } void inisialisasi(void) { F=0; R=-1; COUNTER=0; }
Tidak ada komentar:
Posting Komentar