c++ STL容器队列queue

c++STL学习视频
https://www.bilibili.com/video/av63384955?from=search&seid=5013240884410317680

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include <queue>
using namespace std;
class  teacher
{
	
	
	public :		
	int age;
	char name[32];
		void printf()
		{
			cout<<age<<endl;
		}
};

void int_queue()
{
	queue <int> q;
	q.push(1);
	q.push(2);
	q.push(3); //push(元素)
    q.front() ;
    q.size();
    while(!q.empty())
	{
		cout<<q.front()<<endl;
		q.pop();
	}	
 } 
 void teacher_queue()
 {
 	teacher t1,t2,t3;
	t1.age=31;
	t2.age=19;
	t3.age=45;
 	queue <teacher> q; //队列创建
 	q.push(t1);//入队
 	q.push(t2);
 	q.push(t3);
 	while(!q.empty()) 
 	{  
 	    teacher tmp;
 		tmp=q.front();//出队但不删除
 		tmp.printf();
 		q.pop();//从队列中删除 
	 }
 	
 }
 
  void teacher_queue2()
 {
 	teacher t1,t2,t3;
	t1.age=31;
	t2.age=19;
	t3.age=45;
 	queue <teacher*> q;
 	q.push(&t1);
 	q.push(&t2);
 	q.push(&t3);
 	while(!q.empty()) 
 	{  
 	    teacher* tmp;
 		tmp=q.front();//出来的不是元素,而是元素的地址  
 		tmp->printf();//指针不能用.用->访问  
 		q.pop();
	 }
 	
 }
 int main()
 {
 	
 int_queue();
 teacher_queue();
 teacher_queue2();
 return 0; 
 } 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值