From 894d0dd64db214fc199594942c7c3c892faea540 Mon Sep 17 00:00:00 2001 From: qualifier1024 <102360259+qualifier1024@users.noreply.github.com> Date: Mon, 28 Nov 2022 21:07:55 +0800 Subject: [PATCH] Update queue.cpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 译自大佬的Java代码,更改了部分表述 --- codes/cpp/chapter_stack_and_queue/queue.cpp | 35 +++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/codes/cpp/chapter_stack_and_queue/queue.cpp b/codes/cpp/chapter_stack_and_queue/queue.cpp index d76fca65d..c529a7c00 100644 --- a/codes/cpp/chapter_stack_and_queue/queue.cpp +++ b/codes/cpp/chapter_stack_and_queue/queue.cpp @@ -1,8 +1,39 @@ /* * File: queue.cpp - * Created Time: 2022-11-25 - * Author: Krahets (krahets@163.com) + * Created Time: 2022-11-28 + * Author: qualifier1024 (2539244001@qq.com) */ #include "../include/include.hpp" +int main(){ + /* 初始化队列 */ + queue queue; + + /* 元素入队 */ + queue.push(1); + queue.push(3); + queue.push(2); + queue.push(5); + queue.push(4); + cout << "队列 queue = "; + PrintUtil::printQueue(queue); + + /* 访问队首元素 */ + int front = queue.front(); + cout << "队首元素 front = " << front << endl; + + /* 元素出队 */ + queue.pop(); + cout << "出队元素 front = " << front << ",出队后 queue = "; + PrintUtil::printQueue(queue); + + /* 获取队列的长度 */ + int size = queue.size(); + cout << "队列长度 size = " << size << endl; + + /* 判断队列是否为空 */ + bool isEmpty = queue.empty(); + + return 0; +}