链队列
#include<stdio.h>
#include<stdlib.h>
typedef int datatype;
typedef struct Queuenode{
datatype data;
struct Queuenode *next;
}Node;
typedef struct Queuelink{
struct Queuenode *front,*rear;
}Qlink;
void init(Qlink *q){
q->front = (Node *)malloc(sizeof(Node));
q->front->next = NULL;
q->rear = q->front;
}
void Push(Qlink *q,datatype value){
Node *news;
news = (Node *)malloc(sizeof(Node));
news->data = value;
news->next = NULL;
q->rear->next = news;
q->rear = news;
}
int Pop(Qlink *q){
if(q->front == q->rear){
printf("链队列为空\n");
}else{
datatype x;
x = q->front->next->data;
q->front = q->front->next;
return x;
}
}
void Pankong(Qlink *q){
if(q->front == q->rear){
printf("链队列为空\n");
}else{
printf("链队列不为空\n");
}
}
datatype Getfront(Qlink *q){
return q->front->next->data;
}
转载请注明原文地址:https://ipadbbs.8miu.com/read-51551.html