Advertisement
Guest User

Untitled

a guest
Feb 24th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <iostream>
  3. #include <conio.h>
  4. #include <windows.h>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. int queue[5];
  11. int head = 1;
  12. int tail = -1;
  13. int pilihan, nilai, i;
  14.  
  15. do{
  16. cout<<("MENU\n");
  17. cout<<("1. Enqueue\n2. Dequeue\n3. tampilan\n4. keluar\n");
  18. system("cls");
  19. cout<<("Pilihan = ");
  20. cin>>pilihan;
  21.  
  22. switch (pilihan)
  23. {
  24. case 1:
  25. if (tail < 4 )
  26. {
  27. cout<<"Data Masuk = ";
  28. cin>>nilai;
  29. queue[tail+1] = nilai;
  30. tail++;
  31. if (tail == 0)
  32. head = 0;
  33. }
  34. else
  35. cout<<"Queue penuh\n";
  36. break;
  37. case 2:
  38. if (head <= tail)
  39. {
  40. cout<<"Data keluar = \n"<<queue[head];
  41. head++;
  42. cout<<endl;
  43. }
  44. else
  45. cout<<("queue kosong\n");
  46. break;
  47. case 3:
  48. for(i=head; i<=tail; i++)
  49. cout<<" data ke - "<<i<<" = "<<queue[i];
  50. cout<<"\n";
  51. break;
  52. }
  53. cout<<"--------------------------------------";
  54. cout<<endl;
  55. }
  56. while (pilihan != 4);
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement