#include <iostream>
#include <malloc.h>
using namespace std;
#define MAXSIZE 10
typedef int ElemType;
typedef bool Status;
typedef struct SqQueue {
ElemType* base;
ElemType* q;
int front;
int rear;
}SqQueue;
Status init(SqQueue& Q) {
Q.base = (ElemType*)malloc(MAXSIZE * sizeof(ElemType));
if (!Q.base) {
cout << "空间分配失败!\n";
return false;
}
Q.front = Q.rear = 0;
return true;
}
Status insert(SqQueue& Q) {
if ((Q.rear + 1) % MAXSIZE == Q.front) {
cout << "队列已满\n";
return false;
}
cout << "输入元素值:";
int i;
cin >> i;
Q.base[Q.rear] = i;
Q.rear = (Q.rear + 1) % MAXSIZE;
return true;
}
Status select(SqQueue& Q) {
cout << "所有元素如下:\n";
while (Q.front != (Q.rear + 1) % MAXSIZE) {
cout << Q.base[Q.front] << endl;
Q.front = (Q.front + 1) % MAXSIZE;
}
return true;
}
Status remove(SqQueue& Q) {
if (Q.front == Q.rear) {
cout << "队列为空\n";
return false;
}
ElemType i = Q.base[Q.front];
Q.front = (Q.front + 1) % MAXSIZE;
cout << "元素" << i << "被删除\n";
return true;
}
Status update(SqQueue &Q) {
return true;
}
int main() {
SqQueue S;
init(S);
while (true)
{
cout << "请选择需要进行的操作\n0.退出\t1.插入\t2.查询\t3.删除\t4.修改\t\n";
int choice;
cin >> choice;
if (choice == 0)
{
break;
}
switch (choice)
{
case 1:insert(S); break;
case 2:select(S); break;
case 3:remove(S); break;
case 4:update(S); break;
default:break;
}
}
}