#include<stdio.h>
#include<malloc.h>
#include<time.h>
#include<stdlib.h>
#define ElemType char
typedef struct LQNode
{
ElemType data;//结点的数据域
struct LQNode *next;//定义指向下一结点的指针
}LQNode,*QueuePtr;
typedef struct
{
QueuePtr front;//队头指针
QueuePtr rear;//队尾指针
}LinkQueue;
int InitLQueue(LinkQueue &Q)//初始化队列
{
Q.front=Q.rear=(QueuePtr)malloc(sizeof(LQNode));
if(Q.front == NULL)
{
printf("内存分配失败!\n\n");return -1;
}
Q.front->next=NULL;//初始时后继为空
return 1;
}
int Assignment(LinkQueue &Q)//为队列生成一些初始结点
{
srand((unsigned)time(NULL));
Q.front->data='#';//为头结点的数据域赋值,注意出队列的时候是头结点的后继出队列
for(int i=10;i>0;i--)
{//为队列生成10个结点以便于操作
Q.rear->next=(QueuePtr)malloc(sizeof(LQNode));
Q.rear=Q.rear->next;
Q.rear->data=(char)(rand()%26+'a');
}
Q.rear->next=NULL;//尾结点的后继为空
return 1;
}
int DestroyQueue(LinkQueue &Q)//
建立数据域值为字符型的链式队列
最新推荐文章于 2022-07-06 15:31:21 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)