#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#define MAXSIZE 100
typedef struct{
char isbn[20];
char name[10];
double price;
}Book;
typedef struct Queue{
Book *elem;
int front;
int rear;
}SqQueue;
bool Init_queue(SqQueue *Q);
int Queue_length(SqQueue Q);
bool Enter_queue(SqQueue *Q,Book e);
bool Delete_queue(SqQueue *Q,Book *e);
int main(void)
{
return 0;
}
bool Init_queue(SqQueue *Q)
{
Q->elem = (Book*)malloc(sizeof(Book)*MAXSIZE);
if(!Q->elem)
{
exit(-1);
}
Q->front = 0;
Q->rear = 0;
return true;
}
int Queue_length(SqQueue Q)
{
int length;
length = (Q.rear - Q.front + MAXSIZE)%MAXSIZE;
return length;
}
bool Push_queue(SqQueue *Q,Book e)
{
if((Q->front + 1)%MAXSIZE == Q->rear)
{
return false;
}
Q->elem[Q->rear] = e;
Q->rear = (Q->rear + 1)%MAXSIZE;
return true;
}
bool Delete_queue(SqQueue *Q,Book *e)
{
if(Q->front == Q->rear)
{
return false;
}
*e = Q->elem[Q->front];
Q->front = (Q->front + 1)%MAXSIZE;
return true;
}
数据结构2.4.1顺序队列
最新推荐文章于 2024-11-02 15:22:06 发布