顺序队列的实现基本操作,思考画图辅助代码实现
#include<iostream>
using namespace std;
#define maxsize 4
//顺序实现队列
//循环储存空间避免溢出错误//队列多用链表表示
typedef struct quee
{
int* base;//指向int形数据指针
int front;//对头元素位置
int rear;//对尾元素位置
}quee;
void initialquee(quee& q)
{
q.base = new int[maxsize];//存放maxsiaze-1个数据只能
if (q.base)
{
cout << "队列初始化成功" << endl;
q.front = q.rear = 0;
}
else
cout << "队列初始化失败" << endl;
}//初始化队列
void insertquee(quee& q)
{
int t;
if ((q.rear + 1) % maxsize == q.front)
{
return;//队列满了
}
else
{
cout << "请输入入队的元素" << endl;
cin >> t;
q.base[q.rear] =t ;
q.rear = (q.rear + 1) % maxsize;
}
}//入队列操作
void deletequee(quee& q)
{
if (q.front == q.rear)
{
cout << "队列出空了不能再出队列" << endl;
}
else
{
cout << "出队列的元素为" << q.base[q.front] << endl;
q.front = ++q.front % maxsize;
cout << "队列非空" << endl;
}
}//出队列操作
int main()
{
quee q;
return 0;
}