#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
//#define MAXSIZE 5
typedef int date_t;
typedef struct listqueue {//节点结构体
date_t name_id;
listqueue* next;
}listqueue,*list;
typedef struct queue {//队列结构体
listqueue* front;
listqueue* rear;
int size;
}queue;
void initqueue(queue* node)
{
listqueue* head=new listqueue;
node->front = node->rear = head;
head->next = nullptr;
node->size = 0;
}
bool empty(queue* qulist)
{
return qulist->size == 0;
}
void pushback(date_t name, queue* qulist)
{
listqueue* newqu = new listqueue;
newqu->name_id = name;
newqu->next = nullptr;
if (qulist->size == 0)
{
qulist->front->next = newqu;
}
qulist->rear->next = newqu;
qulist->rear = newqu;
qulist->size++;
}
int pop(queue*qulist)
{
if (empty(qulist))
return -1;
date_t temp = qulist->front->next->name_id;
listqueue* ptemp = qulist->front->next;
qulist->front->next = qulist->front->next->next;
delete ptemp;
qulist->size--;
return temp;
}
void Viewfront(queue* qulist)
{
if (!empty(qulist))
cout << qulist->front->next->name_id << endl;
else
cout << "队列为空" << endl;
}
void Viewrear(queue* qulist)
{
if(!empty(qulist))
cout << qulist->rear->name_id << endl;
else {
cout << "队列为空" << endl;
}
}
void testlistqueue()
{
queue* L=new queue;
initqueue(L);
while (true) {
cout << "\n队列操作:" << endl;
cout << "1. 插入元素" << endl;
cout << "2. 弹出元素" << endl;
cout << "3. 查看队列头元素" << endl;
cout << "4. 获取队列的大小" << endl;
cout << "5. 判断栈是否为空" << endl;
cout << "6.查看队列尾元素" << endl;
cout << "7.判断队列是否为满" << endl;
int choice;
cout << "请选择操作:";
cin >> choice;
switch (choice)
{
case 1:
cout << "请输入插入元素" << endl;
date_t re;cin >> re;
pushback(re,L);
break;
case 2:
cout << pop(L) << endl;
break;
case 3:
Viewfront(L);
break;
case 4:
cout << L->size << endl;
break;
case 5:
cout << empty(L) << endl;
break;
case 6:
Viewrear(L);
break;
case 7:
break;
default:
break;
}
}
}
int main()
{
testlistqueue();
}