#include<iostream>
#include<malloc.h>
#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
typedef struct queue
{
int* pBase;
int front;
int rear;
int len;
}QUEUE;
void init(QUEUE* pQ,int length)
{
pQ->len = length;
pQ->pBase = (int*)malloc(sizeof(int)*(pQ->len));
pQ->front = 0;
pQ->rear = 0;
}
bool full(QUEUE* pQ)
{
if((pQ->rear + 1) % (pQ->len) == pQ->front)
return true;
else
return false;
}
bool en(QUEUE* pQ,int val)
{
if(full(pQ))
return false;
else
pQ->pBase[pQ->rear] = val;
pQ->rear = (pQ->rear + 1) % pQ->len;
return true;
}
void traverse(QUEUE* pQ)
{
int i = pQ->front;
while(i != pQ->rear)
{
printf("%d ",pQ->pBase[i]);
i = (i+1) % pQ->len;
}
return;
}
bool emput(QUEU
队列的创建与基本操作(c++实现,完整版)
于 2023-08-12 16:31:45 首次发布