Advertisement
wendy890711

191018-2

Oct 18th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 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 = -1, end = -1; };
  9. void enqueue();
  10. void dequeue();
  11. private:
  12. int start, end;
  13. int array[Maxsize];
  14. };
  15.  
  16. void queue::enqueue(){
  17. if (end >= Maxsize - 1)
  18. cout << "滿了" << endl;
  19. else{
  20. end++;
  21. cout << "請輸入整數" << endl;
  22. cin >> array[end];
  23. }
  24. }
  25.  
  26. void queue::dequeue(){
  27. if (start >= Maxsize - 1)
  28. cout << "空了" << endl;
  29. else{
  30. start++;
  31. cout << array[start]<<endl;
  32. }
  33. }
  34. int main()
  35. {
  36. queue s1;
  37. s1.init();
  38. for (int i = 1; i < 7; i++)
  39. s1.enqueue();
  40. for (int i = 1; i < 7; i++)
  41. s1.dequeue();
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement