Advertisement
putriagust

queue

Jul 11th, 2020
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. /*
  2.  
  3. ALGGORITMA STRUKTUR DATA (S1IF-07-F)
  4. Nama : Putri Agustyaningsih
  5. NIM : 19102208
  6.  
  7. */
  8.  
  9. #include <iostream>
  10. #include <windows.h>
  11. #include <conio.h>
  12. #define MAX 8
  13.  
  14. using namespace std;
  15.  
  16. struct queue{
  17. string nama[MAX];
  18. int head;
  19. int tail;
  20. }antrian;
  21.  
  22. void setAwal(){
  23. antrian.head=antrian.tail=-1;
  24. }
  25.  
  26. int IsEmpty(){
  27. if(antrian.tail==-1)
  28. return 1;
  29. else
  30. return 0;
  31. }
  32. int IsFull(){
  33. if(antrian.tail==MAX-1)
  34. return 1;
  35. else
  36. return 0;
  37. }
  38.  
  39. void Enqueue(struct queue** head, string nama){
  40. if(IsEmpty()==1){
  41. antrian.head=antrian.tail=1;
  42. antrian.nama[antrian.tail]=nama;
  43. cout<<nama<<endl;
  44. }else if (IsEmpty() == 0){
  45. antrian.tail++;
  46. antrian.nama[antrian.tail]=nama;
  47. cout << antrian.nama[antrian.tail] << endl;
  48. }
  49. }
  50.  
  51. string Dequeue(){
  52. if (IsEmpty() == 0){
  53. string e = antrian.nama[antrian.head];
  54. for(int i=antrian.head;i<=antrian.tail-1;i++){
  55. antrian.nama[i] = antrian.nama[i+1];
  56. }
  57. antrian.tail--;
  58. cout << "Data keluar.";
  59. return e;
  60. }else
  61. cout << "kosong.";
  62. }
  63.  
  64. void Tampil(){
  65. if(IsEmpty()==0){
  66. for(int i=antrian.head;i<=antrian.tail;i++){
  67. cout<<antrian.nama[i] << endl;
  68. }
  69. }else{
  70. cout<<"kosong.";
  71. }
  72. }
  73.  
  74. int main()
  75. {
  76. int pil;
  77. string nama;
  78. struct queue* head = NULL;
  79. do{
  80. system ("cls");
  81. cout<< "\n\n MENU PROGRAM\n\n";
  82. cout<<"1. Daftar Buku Awal\n";
  83. cout<<"2. Pindahkan Buku yang Sudah Dibaca\n";
  84. cout<<"3. Daftar Sisa Buku yang Belum Dibaca\n";
  85. cout<<"4. Exit\n";
  86. cout<< "\n Pilihan : ";
  87. cin>>pil;
  88. cout<<endl;
  89.  
  90. switch(pil){
  91. case 1:
  92. cout << " Daftar Buku Yang Ada: \n" <<endl;
  93. Enqueue(&head, " Risang Abdurrahman Gustiwa");
  94. Enqueue(&head, " Salsabila Firda Yunita");
  95. Enqueue(&head, " Fakhri Febriansyah");
  96. Enqueue(&head, " Putri Agustyaningsih");
  97. Enqueue(&head, " Juliar Ma'arif");
  98. Enqueue(&head, " Martinus Rexyfarrel Evan Sayoga");
  99. Enqueue(&head, " Galuh Kusuma Wardhani");
  100. getch();
  101. break;
  102. case 2:
  103. Dequeue();
  104. getch();
  105. break;
  106. case 3:
  107. Tampil();
  108. getch();
  109. break;
  110. case 4:
  111. system("EXIT");
  112. break;
  113. default:
  114. cout<<"Pilihan tidak tersedia";
  115. break;
  116. }
  117. cout << endl;
  118. system("pause");
  119. } while(pil!=4);
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement