如果允许在循环队列的两端都可以进行插入和删除操作。要求:写出“从队尾删除”和“从队头插入”的算法;
#include <iostream >
using namespace std;
template <typename ElemType>
struct Quene {ElemType* items;int head, tail;//队列的头、尾指针int length;//当前存储的元素数量int capacity;//队列容量Quene(int c) {head = tail = 0;//头指针,尾指针为0,队列为空length = 0;capacity = c;items = new ElemType[capacity];if (!items)exit(OVERFLOW);}~Quene() { delete[]items; }//析构函数,释放动态申请的存储空void Push_head(Quene& Q, ElemType e) {//从队头入队
本文发布于:2024-02-04 14:56:01,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170709825556564.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |