1. Definiation
What is a queue?
A queue is a list. With a queue, inseration is done at one end (known as rear) whereas deletion is performed at the other end (known as front).

2. Operations
指针对列
无法自定义队长
// array queue #include<iostream> using namespace std; struct Node { int data; }; class Queue { public: //初始化 Queue() { front = -1; rear = -1; } //判断是否为空 bool isEmpty() { if (rear == front) return true; return false; } //判队满 bool isFull() { if (rear - front == 10) return true; return false; } //入队列 void EnQueue(int item) { if (!isFull()) { rear += 1; node[rear].data = item; } else { cout << "Full" << endl; } } //出队列 void DiQueue() { if (!isEmpty()) { front += 1; } else { cout << "Empty" << endl; } } //取队头 int GetHead() { if (!isEmpty()) { int temp = node[front+1].data; return temp; } else { cout << "Empty" << endl; return 0; } } //得队长 int GetSize() { return rear - front; } private: int front; //队头指针总是指向队头元素的前一个位置 int rear; Node node[10]; };
讯享网

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/40095.html