mirror of
https://github.com/krahets/hello-algo.git
synced 2026-11-10 07:49:44 +08:00
* Retranslate the complete English edition from Simplified Chinese * Polish three English explanations after reader-focused review
42 lines
920 B
C++
42 lines
920 B
C++
/**
|
|
* File: queue.cpp
|
|
* Created Time: 2022-11-28
|
|
* Author: qualifier1024 (2539244001@qq.com)
|
|
*/
|
|
|
|
#include "../utils/common.hpp"
|
|
|
|
/* Driver code */
|
|
int main() {
|
|
/* Initialize the queue */
|
|
queue<int> queue;
|
|
|
|
/* Enqueue elements */
|
|
queue.push(1);
|
|
queue.push(3);
|
|
queue.push(2);
|
|
queue.push(5);
|
|
queue.push(4);
|
|
cout << "Queue queue = ";
|
|
printQueue(queue);
|
|
|
|
/* Access the front element */
|
|
int front = queue.front();
|
|
cout << "Front element front = " << front << endl;
|
|
|
|
/* Dequeue an element */
|
|
queue.pop();
|
|
cout << "Dequeued element front = " << front << "; after dequeueing, queue = ";
|
|
printQueue(queue);
|
|
|
|
/* Get the queue size */
|
|
int size = queue.size();
|
|
cout << "Queue size = " << size << endl;
|
|
|
|
/* Check whether the queue is empty */
|
|
bool empty = queue.empty();
|
|
cout << "Is the queue empty = " << empty << endl;
|
|
|
|
return 0;
|
|
}
|