#include <stdio.h>
#include <stdlib.h>
#define maxsize 100
typedef int ElemType;
typedef struct QNode{
ElemType data;
struct QNode* next;
}QNode,* QuenePtr;
typedef struct {
QuenePtr front;
QuenePtr rear;
}LinkQueue;
void InitQueue(LinkQueue& S) {
S.front = S.rear = (QuenePtr)malloc(sizeof(struct QNode));
}
void Destroy(LinkQueue& s) {
QuenePtr p = s.front;
while (s.front) {
p = s.front->next;
free(s.front);
s.front = p;
//s.rear = s.front->next;
//free(s.front);
//s.front = s.rear
}
}
int QueueLength(LinkQueue Q) {
}
int EnQueue(LinkQueue& s, ElemType x) {
QuenePtr p = (QuenePtr)malloc(sizeof(struct QNode));
p->data = x;
p->next = NULL;
s.rear->next = p;
s.rear = p;
return 1;
}
int DeQueue(LinkQueue& s, ElemType& x) {
if (s.front == s.rear)return 0;
QuenePtr p = (QuenePtr)malloc(sizeof(QNode));
p = s.front->next;
x = s.front->data;
if (p == s.rear)s.rear = s.front;
free(p);
return 1;
}
int SqQueneEmpty(LinkQueue& s) {
if (s.front == s.rear)return 1;
return 0;
}
ElemType GetHead(LinkQueue Q) {
if (Q.front == Q.rear)return 0;
return Q.front->next->data;
}
队列链表c语言实现
最新推荐文章于 2024-11-03 21:27:26 发布