实现链队类
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user