2023-01-06 03:39:19 +08:00
|
|
|
/**
|
2022-11-25 02:04:38 +08:00
|
|
|
* File: queue.cpp
|
2022-11-28 21:07:55 +08:00
|
|
|
* Created Time: 2022-11-28
|
|
|
|
* Author: qualifier1024 (2539244001@qq.com)
|
2022-11-25 02:04:38 +08:00
|
|
|
*/
|
|
|
|
|
2022-11-27 04:19:16 +08:00
|
|
|
#include "../include/include.hpp"
|
|
|
|
|
2022-11-29 02:21:49 +08:00
|
|
|
/* Driver Code */
|
2023-04-14 03:44:02 +08:00
|
|
|
int main() {
|
2022-11-28 21:07:55 +08:00
|
|
|
/* 初始化队列 */
|
|
|
|
queue<int> queue;
|
2023-04-14 03:44:02 +08:00
|
|
|
|
2022-11-28 21:07:55 +08:00
|
|
|
/* 元素入队 */
|
|
|
|
queue.push(1);
|
|
|
|
queue.push(3);
|
|
|
|
queue.push(2);
|
|
|
|
queue.push(5);
|
|
|
|
queue.push(4);
|
|
|
|
cout << "队列 queue = ";
|
2023-04-14 03:44:02 +08:00
|
|
|
printQueue(queue);
|
|
|
|
|
2022-11-28 21:07:55 +08:00
|
|
|
/* 访问队首元素 */
|
|
|
|
int front = queue.front();
|
|
|
|
cout << "队首元素 front = " << front << endl;
|
2023-04-14 03:44:02 +08:00
|
|
|
|
2022-11-28 21:07:55 +08:00
|
|
|
/* 元素出队 */
|
|
|
|
queue.pop();
|
|
|
|
cout << "出队元素 front = " << front << ",出队后 queue = ";
|
2023-04-14 03:44:02 +08:00
|
|
|
printQueue(queue);
|
|
|
|
|
2022-11-28 21:07:55 +08:00
|
|
|
/* 获取队列的长度 */
|
|
|
|
int size = queue.size();
|
|
|
|
cout << "队列长度 size = " << size << endl;
|
2023-04-14 03:44:02 +08:00
|
|
|
|
2022-11-28 21:07:55 +08:00
|
|
|
/* 判断队列是否为空 */
|
2022-11-30 02:27:26 +08:00
|
|
|
bool empty = queue.empty();
|
|
|
|
cout << "队列是否为空 = " << empty << endl;
|
2023-04-14 03:44:02 +08:00
|
|
|
|
2022-11-28 21:07:55 +08:00
|
|
|
return 0;
|
|
|
|
}
|