第四题完成
This commit is contained in:
+10
-3
@@ -7,6 +7,7 @@ using namespace std;
|
||||
|
||||
void initQueue(linkQueue &q) {
|
||||
q.list = new Node;
|
||||
q.list->next = NULL;
|
||||
q.front = q.rear = q.list;
|
||||
}
|
||||
|
||||
@@ -17,9 +18,10 @@ bool isEmpty(linkQueue &q) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool enQueue(linkQueue &q, int e) {
|
||||
void enQueue(linkQueue &q, int e) {
|
||||
q.rear->next = new Node;
|
||||
q.rear->next->data = e;
|
||||
q.rear = q.rear->next;
|
||||
q.rear->data = e;
|
||||
}
|
||||
|
||||
int deQueue(linkQueue &q) {
|
||||
@@ -27,7 +29,12 @@ int deQueue(linkQueue &q) {
|
||||
cout << "此队列为空" << endl;
|
||||
return NULL;
|
||||
}
|
||||
Node *temp = q.front->next;
|
||||
q.front = temp;
|
||||
int returnE = q.front->data;
|
||||
q.front = q.front->next;
|
||||
delete temp;
|
||||
if (q.front->next == NULL) {
|
||||
q.rear = q.front;
|
||||
}
|
||||
return returnE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user