Advertisement
Guest User

Untitled

a guest
Feb 26th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <stdlib.h>
  4. #define max 5
  5.  
  6. using namespace std ;
  7.  
  8.  
  9. int data[max];
  10. int kepala = -1, ekor= -1, a;
  11.  
  12. bool IsFull()
  13. {
  14. if (ekor == max - 1)
  15. return true;
  16. else
  17. return false;
  18. }
  19.  
  20. bool IsEmpty()
  21. {
  22. if (kepala == -1 && ekor == -1)
  23. return true;
  24. else
  25. return false;
  26. }
  27.  
  28.  
  29. void Enqueue()
  30. {
  31. if (IsFull())
  32. {
  33. cout << "Data penuh";
  34. }
  35. else
  36. {
  37. if (IsEmpty())
  38. {
  39. kepala = ekor = 0;
  40. cout << "Masukkan data : "; cin >> data[ekor];
  41. }
  42. else
  43. {
  44. ekor++;
  45. cout << "Masukkan data : "; cin >> data[ekor];
  46. }
  47. }
  48. }
  49.  
  50.  
  51. void Dequeue()
  52. {
  53. if (IsEmpty())
  54. {
  55. cout << "Data kosong";
  56. getch();
  57. }
  58. else
  59. {
  60. cout << "Ambil data: " << data[kepala];
  61. for (a = kepala; a <= ekor - 1; a++)
  62. data[a] = data[a + 1];
  63. ekor--;
  64. if (kepala == -1)
  65. kepala = -1;
  66. getch();
  67. }
  68. }
  69.  
  70.  
  71. void Clear()
  72. {
  73. kepala = ekor = -1;
  74. cout << "Seluruh data sudah dihapus"; getch();
  75. }
  76.  
  77.  
  78. void View()
  79. {
  80. if (IsEmpty())
  81. {
  82. cout << "Data kosong";
  83. getch();
  84. }
  85. else
  86. {
  87. for (a = kepala; a <= ekor; a++)
  88. cout << "Data pada antrian ke " << a << " = " << data[a] << endl;
  89. getch();
  90. }
  91. }
  92.  
  93. int main()
  94. {
  95. int pilih;
  96. do
  97. {
  98. if (system("CLS")) system("clear");
  99. cout << "1. Enqueue " << endl;
  100. cout << "2. Dequeue " << endl;
  101. cout << "3. Clear " << endl;
  102. cout << "4. View " << endl;
  103. cout << "5. Exit " << endl;
  104. cout << "Masukkan pilihan Anda : ";
  105. cin >> pilih;
  106. switch (pilih)
  107. {
  108. case 1:
  109. Enqueue(); break;
  110. case 2:
  111. Dequeue(); break;
  112. case 3:
  113. Clear(); break;
  114. case 4:
  115. View(); break;
  116. }
  117. } while (pilih != 5);
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement