//练习队列的使用
#include<iostream>
#include<queue>
using namespace std;
struct ps{
int a;
int b;
};
void add(ps pb[],int n)
{
queue<ps>q;
for(int i=0;i<n;i++)
{
pb[i].a=i;
pb[i].b=i+1;
q.push(pb[i]);
cout<<q.front().a+1<<" ";
q.pop();
}
}
int main()
{
ps pb[100];
int n=5;
add(pb,n);
return 0;
}
举一反三,STL 中queue的练习
本文介绍了一个使用C++标准模板库(STL)中的队列数据结构的简单示例。通过定义结构体并使用队列进行元素的添加与移除操作,演示了队列的基本用法。该示例适用于初学者理解队列的工作原理。


被折叠的 条评论
为什么被折叠?



