Advertisement
wendy890711

20191108

Nov 8th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. using namespace std;
  4. #define Maxsize 5
  5.  
  6. class queue{
  7. public:
  8. void init(){ start = Maxsize - 1, end = start, tag = 0; };
  9. void enqueue(int);
  10. void dequeue();
  11. private:
  12. int start, end, tag;
  13. int array[Maxsize];
  14. };
  15.  
  16. void queue::enqueue(int in){
  17. if (start == end&&tag == 1)
  18. cout << "Queue is full" << endl;
  19. else{
  20. end = (end + 1) % Maxsize;
  21. array[end] = in;
  22. if (start == end)
  23. {
  24. tag = 1;
  25. }
  26. }
  27.  
  28. }
  29.  
  30. void queue::dequeue(){
  31. if (start ==end && tag==0)
  32. cout << "η©ΊδΊ†" << endl;
  33. else{
  34. start=(start+1)%Maxsize;
  35. cout << "item" << array[start] << "delete" << endl;
  36. if (start == end)
  37. tag = 0;
  38. }
  39. }
  40. int main()
  41. {
  42. queue s1;
  43. s1.init();
  44. for (int i = 1; i < 4; i++)
  45. {
  46. int n;
  47. cout << "please enter the item" << endl;
  48. cin >> n;
  49. s1.enqueue(n);
  50. }
  51. for (int i = 1; i < 3; i++)
  52. s1.dequeue();
  53. for (int i = 1; i < 6; i++)
  54. {
  55. int n;
  56. cout << "please enter the item" << endl;
  57. cin >> n;
  58. s1.enqueue(n);
  59. }
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement