#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<malloc.h>
typedef struct LinkNode{
int data;
struct LinkNode* next;
}LinkQueue;
typedef struct {
LinkNode* front, * rear;
}*LinkQueue;
void InitQueue(LinkQueue& Q)
{
Q->front = Q->rear = (LinkNode*)malloc(sizeof(LinkNode));
Q->front->next = NULL;
}//初始化
bool IsEmpty(LinkQueue& Q)
{
if (Q->front == Q->rear)
return true;
else
return false;
}//链队判空
void EnQueue(LinkQueue& Q,int x)
{
LinkNode* s = (LinkNode*)malloc(sizeof(LinkNode));
s->data = x;
s->next = NULL;
Q->rear->next = s;
Q->rear = s;
int tag = 1;
}//入队
bool DeQueue(LinkQueue& Q, int& x)
{
if (Q->front == Q->rear)
return false;
LinkNode* p = Q->front->next;
x = p->data;
Q->front->next=p->next;
if (Q->rear == p)
Q->rear = Q->front;
free(p);
int tag = 0;
return true;
}//出队
bool IsEmpty2(LinkQueue& Q,int tag)
{
if (tag == 1)
return true;
else
return false;
}//栈判空tag变量法
int main()
{
LinkQueue Q;
InitQueue(Q);
IsEmpty(Q);
IsEmpty2(Q);
EnQueue(Q, x);
DeQueue(Q, &x);
}
队列链式存储(伪代码)
最新推荐文章于 2024-07-25 17:57:45 发布