41 lines
733 B
C++
41 lines
733 B
C++
//LinkQueue.cpp
|
|
|
|
#include "LinkQueue.h"
|
|
#include<iostream>
|
|
|
|
using namespace std;
|
|
|
|
void initQueue(linkQueue &q) {
|
|
q.list = new Node;
|
|
q.list->next = NULL;
|
|
q.front = q.rear = q.list;
|
|
}
|
|
|
|
bool isEmpty(linkQueue &q) {
|
|
if (q.front == q.rear) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void enQueue(linkQueue &q, int e) {
|
|
q.rear->next = new Node;
|
|
q.rear->next->data = e;
|
|
q.rear = q.rear->next;
|
|
}
|
|
|
|
int deQueue(linkQueue &q) {
|
|
if (isEmpty(q)) {
|
|
cout << "此队列为空" << endl;
|
|
return NULL;
|
|
}
|
|
Node *temp = q.front->next;
|
|
q.front = temp;
|
|
int returnE = q.front->data;
|
|
delete temp;
|
|
if (q.front->next == NULL) {
|
|
q.rear = q.front;
|
|
}
|
|
return returnE;
|
|
}
|