/*
不带头结点的链式队列进出队操作
*/
#include <stdio.h>
#include <stdlib.h>
#define ElementType int
typedef struct QNode *Queue;
typedef struct Node{
ElementType Data;
struct Node *Next;
};
typedef struct QNode{
struct Node *front;
struct Node *rear;
};
void InintQueue(Queue &PtrQ){//虽然是指针,但是没赋值之前也不能乱指
PtrQ = (Queue)malloc(sizeof(struct QNode));
PtrQ->front=PtrQ->rear=NULL;
}
bool EnQueue(Queue PtrQ, ElementType X){
struct Node *RearCell = PtrQ->rear;
struct Node *Tmp = (struct Node *)malloc(sizeof(struct Node));
Tmp->Data = X;
Tmp->Next=NULL;
if(PtrQ->front==NULL)//队列为空,进第一个元素
PtrQ->rear=PtrQ->front=Tmp;
else{
PtrQ->rear->Next = Tmp;
PtrQ->rear = Tmp;
}
return true;
}
ElementType DeleteQ(Queue PtrQ){
struct Node *FrontCell;
ElementType Front
不带头结点的链式队列进出队操作
最新推荐文章于 2023-06-30 10:45:25 发布