image.png

    1. #include<iostream>
    2. using namespace std;
    3. //队列
    4. class SeQueue {
    5. public:
    6. //a.数据成员
    7. int num[10];
    8. int front;
    9. int rear;
    10. //b.构造函数
    11. SeQueue(){
    12. front = 0;
    13. rear = 0;
    14. }
    15. //c.判空
    16. bool Empty_SeQueue(){
    17. if (front == rear) {
    18. return true;
    19. }
    20. return false;
    21. }
    22. //d.判满
    23. bool Full_SeQueue() {
    24. if (rear == 9) {
    25. return true;
    26. }
    27. return false;
    28. }
    29. //e.进队
    30. void Push_SeQueue(int n) {
    31. if (!Full_SeQueue()) {
    32. num[rear++] = n;
    33. }
    34. else {
    35. return;
    36. }
    37. }
    38. //f.出队
    39. void Pop_SeQueue() {
    40. if (!Empty_SeQueue()) {
    41. front++;
    42. }
    43. }
    44. //g.返回front的值
    45. int back_front() {
    46. return front;
    47. }
    48. //h.返回rear的值
    49. int back_rear() {
    50. return rear;
    51. }
    52. };
    53. int main() {
    54. SeQueue dui;
    55. dui.Push_SeQueue(7);
    56. dui.Push_SeQueue(1);
    57. dui.Push_SeQueue(2);
    58. dui.Push_SeQueue(3);
    59. dui.Push_SeQueue(4);
    60. dui.Push_SeQueue(5);
    61. dui.Push_SeQueue(6);
    62. dui.Push_SeQueue(7);
    63. dui.Push_SeQueue(8);
    64. dui.Push_SeQueue(9);
    65. dui.Push_SeQueue(11);
    66. dui.Push_SeQueue(12);
    67. dui.Pop_SeQueue();
    68. cout << dui.back_front() << endl;
    69. cout << dui.back_rear() << endl;
    70. return 0;
    71. }