diff --git a/codes/cpp/chapter_stack_and_queue/array_queue.cpp b/codes/cpp/chapter_stack_and_queue/array_queue.cpp index 387ffd142..8e87da501 100644 --- a/codes/cpp/chapter_stack_and_queue/array_queue.cpp +++ b/codes/cpp/chapter_stack_and_queue/array_queue.cpp @@ -50,11 +50,10 @@ public: } /* 出队 */ - int poll() { + void poll() { int num = peek(); // 队头指针向后移动一位,若越过尾部则返回到数组头部 front = (front + 1) % capacity(); - return num; } /* 访问队首元素 */ @@ -98,8 +97,8 @@ int main() { cout << "队首元素 peek = " << peek << endl; /* 元素出队 */ - int poll = queue->poll(); - cout << "出队元素 poll = " << poll << ",出队后 queue = "; + queue->poll(); + cout << "出队元素 poll = " << peek << ",出队后 queue = "; PrintUtil::printVector(queue->toVector()); /* 获取队列的长度 */ diff --git a/codes/cpp/chapter_stack_and_queue/array_stack.cpp b/codes/cpp/chapter_stack_and_queue/array_stack.cpp index 517a18a4d..e9ecae2a8 100644 --- a/codes/cpp/chapter_stack_and_queue/array_stack.cpp +++ b/codes/cpp/chapter_stack_and_queue/array_stack.cpp @@ -28,10 +28,9 @@ public: } /* 出栈 */ - int pop() { + void pop() { int oldTop = top(); stack.pop_back(); - return oldTop; } /* 访问栈顶元素 */ @@ -67,8 +66,8 @@ int main() { cout << "栈顶元素 top = " << top << endl; /* 元素出栈 */ - int pop = stack->pop(); - cout << "出栈元素 pop = " << pop << ",出栈后 stack = "; + stack->pop(); + cout << "出栈元素 pop = " << top << ",出栈后 stack = "; PrintUtil::printVector(stack->toVector()); /* 获取栈的长度 */ diff --git a/codes/cpp/chapter_stack_and_queue/linkedlist_queue.cpp b/codes/cpp/chapter_stack_and_queue/linkedlist_queue.cpp index dcaac225f..10cba0aaf 100644 --- a/codes/cpp/chapter_stack_and_queue/linkedlist_queue.cpp +++ b/codes/cpp/chapter_stack_and_queue/linkedlist_queue.cpp @@ -47,7 +47,7 @@ public: } /* 出队 */ - int poll() { + void poll() { int num = peek(); // 删除头结点 ListNode *tmp = front; @@ -55,7 +55,6 @@ public: // 释放内存 delete tmp; queSize--; - return num; } /* 访问队首元素 */ @@ -97,8 +96,8 @@ int main() { cout << "队首元素 peek = " << peek << endl; /* 元素出队 */ - int poll = queue->poll(); - cout << "出队元素 poll = " << poll << ",出队后 queue = "; + queue->poll(); + cout << "出队元素 poll = " << peek << ",出队后 queue = "; PrintUtil::printVector(queue->toVector()); /* 获取队列的长度 */ diff --git a/codes/cpp/chapter_stack_and_queue/linkedlist_stack.cpp b/codes/cpp/chapter_stack_and_queue/linkedlist_stack.cpp index 312b75135..cf6f6ab3d 100644 --- a/codes/cpp/chapter_stack_and_queue/linkedlist_stack.cpp +++ b/codes/cpp/chapter_stack_and_queue/linkedlist_stack.cpp @@ -37,14 +37,13 @@ public: } /* 出栈 */ - int pop() { + void pop() { int num = top(); ListNode *tmp = stackTop; stackTop = stackTop->next; // 释放内存 delete tmp; stkSize--; - return num; } /* 访问栈顶元素 */ @@ -86,8 +85,8 @@ int main() { cout << "栈顶元素 top = " << top << endl; /* 元素出栈 */ - int pop = stack->pop(); - cout << "出栈元素 pop = " << pop << ",出栈后 stack = "; + stack->pop(); + cout << "出栈元素 pop = " << top << ",出栈后 stack = "; PrintUtil::printVector(stack->toVector()); /* 获取栈的长度 */