mirror of
https://github.com/krahets/hello-algo.git
synced 2024-12-25 12:56:29 +08:00
Update queue.cpp
译自大佬的Java代码,更改了部分表述
This commit is contained in:
parent
9eb9168317
commit
894d0dd64d
1 changed files with 33 additions and 2 deletions
|
@ -1,8 +1,39 @@
|
||||||
/*
|
/*
|
||||||
* File: queue.cpp
|
* File: queue.cpp
|
||||||
* Created Time: 2022-11-25
|
* Created Time: 2022-11-28
|
||||||
* Author: Krahets (krahets@163.com)
|
* Author: qualifier1024 (2539244001@qq.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../include/include.hpp"
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
/* 初始化队列 */
|
||||||
|
queue<int> 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;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue