Advertisement
cyjyj_0524

queue_array

Oct 18th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. // ConsoleApplication8.cpp : 定義主控台應用程式的進入點。
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. using namespace std;
  7. #define maxsize 5
  8. class queue{
  9. public:
  10. void init(){ start = -1; end = -1; }
  11. void enqueue();
  12. void dequeue();
  13. private:
  14. int start, end;
  15. int arr[maxsize];
  16. };
  17.  
  18. void queue::enqueue(){
  19. if (end >= maxsize-1){
  20. cout << "queue is fulled!" << endl;
  21. }
  22. else{
  23. cout << "please enter number to insert: ";
  24. cin >> arr[++end];
  25. }
  26. }
  27.  
  28. void queue::dequeue(){
  29. if (start == end){
  30. cout << "queue is empty!" << endl;
  31. return;
  32. }
  33. else{
  34. cout << arr[++start] << endl;
  35. }
  36. }
  37.  
  38.  
  39. void main()
  40. {
  41. queue Q;
  42. Q.init();
  43. int num;
  44. for (int i = 0; i < 6; i++){
  45. Q.enqueue();
  46. }
  47. for (int i = 0; i < 6; i++){
  48. Q.dequeue();
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement