实现链队类

This commit is contained in:
2024-10-24 01:08:59 +08:00
parent 8d3fdd54dd
commit 2a858769de
2 changed files with 45 additions and 0 deletions
+27
View File
@@ -4,3 +4,30 @@
#include<iostream>
using namespace std;
void initQueue(linkQueue &q) {
q.list = new Node;
q.front = q.rear = q.list;
}
bool isEmpty(linkQueue &q) {
if (q.front == q.rear) {
return true;
}
return false;
}
bool enQueue(linkQueue &q, int e) {
q.rear = q.rear->next;
q.rear->data = e;
}
int deQueue(linkQueue &q) {
if (isEmpty(q)) {
cout << "此队列为空" << endl;
return NULL;
}
int returnE = q.front->data;
q.front = q.front->next;
return returnE;
}
+18
View File
@@ -3,5 +3,23 @@
#ifndef LINKQUEUE_H
#define LINKQUEUE_H
typedef struct Node {
int data;
Node *next;
} Node, *LinkList;
typedef struct {
LinkList list;
Node *front;
Node *rear;
} linkQueue;
void initQueue(linkQueue &q);
bool isEmpty(linkQueue &q);
bool enQueue(linkQueue &q, int e);
int deQueue(linkQueue &q);
#endif //LINKQUEUE_H