实现链队类
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user