Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ALGGORITMA STRUKTUR DATA (S1IF-07-F)
- Nama : Putri Agustyaningsih
- NIM : 19102208
- */
- #include <iostream>
- #include <windows.h>
- #include <conio.h>
- #define MAX 8
- using namespace std;
- struct queue{
- string nama[MAX];
- int head;
- int tail;
- }antrian;
- void setAwal(){
- 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 Enqueue(struct queue** head, string nama){
- if(IsEmpty()==1){
- antrian.head=antrian.tail=1;
- antrian.nama[antrian.tail]=nama;
- cout<<nama<<endl;
- }else if (IsEmpty() == 0){
- antrian.tail++;
- antrian.nama[antrian.tail]=nama;
- cout << antrian.nama[antrian.tail] << endl;
- }
- }
- string Dequeue(){
- if (IsEmpty() == 0){
- string e = antrian.nama[antrian.head];
- for(int i=antrian.head;i<=antrian.tail-1;i++){
- antrian.nama[i] = antrian.nama[i+1];
- }
- antrian.tail--;
- cout << "Data keluar.";
- return e;
- }else
- cout << "kosong.";
- }
- void Tampil(){
- if(IsEmpty()==0){
- for(int i=antrian.head;i<=antrian.tail;i++){
- cout<<antrian.nama[i] << endl;
- }
- }else{
- cout<<"kosong.";
- }
- }
- int main()
- {
- int pil;
- string nama;
- struct queue* head = NULL;
- do{
- system ("cls");
- cout<< "\n\n MENU PROGRAM\n\n";
- cout<<"1. Daftar Buku Awal\n";
- cout<<"2. Pindahkan Buku yang Sudah Dibaca\n";
- cout<<"3. Daftar Sisa Buku yang Belum Dibaca\n";
- cout<<"4. Exit\n";
- cout<< "\n Pilihan : ";
- cin>>pil;
- cout<<endl;
- switch(pil){
- case 1:
- cout << " Daftar Buku Yang Ada: \n" <<endl;
- Enqueue(&head, " Risang Abdurrahman Gustiwa");
- Enqueue(&head, " Salsabila Firda Yunita");
- Enqueue(&head, " Fakhri Febriansyah");
- Enqueue(&head, " Putri Agustyaningsih");
- Enqueue(&head, " Juliar Ma'arif");
- Enqueue(&head, " Martinus Rexyfarrel Evan Sayoga");
- Enqueue(&head, " Galuh Kusuma Wardhani");
- getch();
- break;
- case 2:
- Dequeue();
- getch();
- break;
- case 3:
- Tampil();
- getch();
- break;
- case 4:
- system("EXIT");
- break;
- default:
- cout<<"Pilihan tidak tersedia";
- break;
- }
- cout << endl;
- system("pause");
- } while(pil!=4);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement