Dark horse programmer C++ improves 6-queue container [queue]

Insert picture description here

#include<queue>
#include<iostream>
using namespace std;

void test01() {
    
    

	//初始化
	queue<int> q1;		//默认构造
	queue<int> q2(q1);	//拷贝构造

	//存取操作
	q1.push(10);
	q1.push(20);
	q1.push(30);
	q1.push(40);
	q1.push(100);
	cout << "此时的队首元素front:" << q1.front() << endl;
	cout << "此时的队尾元素back:" << q1.back() << endl;
	q1.pop();
	cout << "此时的队首元素front:" << q1.front() << endl;
	cout << "此时的队尾元素back:" << q1.back() << endl;
	
	cout << "q2.size: " << q2.size() << endl;
	//赋值
	q2 = q1;
	cout << "q2.size: " << q2.size() << endl;

	//打印栈容器数据
	while (!q2.empty()) {
    
    
		cout << q2.front() << " ";
		q2.pop();
	}
}

int main() {
    
    

	test01();
	
	cout << endl << endl;
	return 0;
}

Guess you like

Origin blog.csdn.net/qq_43685399/article/details/108610731