cpp-algo-cases/chapter_stack_and_queue/queue.cpp

42 lines
832 B
C++
Raw Normal View History

2024-02-20 16:13:23 +08:00
/**
* File: queue.cpp
* Created Time: 2022-11-28
* Author: qualifier1024 (2539244001@qq.com)
*/
#include "../utils/common.hpp"
/* Driver Code */
int main() {
/* <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
queue<int> queue;
/* Ԫ<><D4AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
queue.push(1);
queue.push(3);
queue.push(2);
queue.push(5);
queue.push(4);
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD> queue = ";
printQueue(queue);
/* <20><><EFBFBD>ʶ<EFBFBD><CAB6><EFBFBD>Ԫ<EFBFBD><D4AA> */
int front = queue.front();
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԫ<EFBFBD><EFBFBD> front = " << front << endl;
/* Ԫ<>س<EFBFBD><D8B3><EFBFBD> */
queue.pop();
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԫ<EFBFBD><EFBFBD> front = " << front << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӻ<EFBFBD> queue = ";
printQueue(queue);
/* <20><>ȡ<EFBFBD><C8A1><EFBFBD>еij<D0B5><C4B3><EFBFBD> */
int size = queue.size();
cout << "<EFBFBD><EFBFBD><EFBFBD>г<EFBFBD><EFBFBD><EFBFBD> size = " << size << endl;
/* <20>ж϶<D0B6><CFB6><EFBFBD><EFBFBD>Ƿ<EFBFBD>Ϊ<EFBFBD><CEAA> */
bool empty = queue.empty();
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>Ϊ<EFBFBD><EFBFBD> = " << empty << endl;
return 0;
}