一次创建多个队列 [英] Create Multiple Queues at Once

查看:58
本文介绍了一次创建多个队列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法一次创建多个队列?

Is there a way i can create multiple queues at once?

例如我的程序会问.用户想要多少个队列,如果他提交 3 个,那么它会创建 3 个看起来像这样的队列.

For example my program will ask. How many queues the user wants, if he submits 3 then it will create 3 queues that look like this.

queue<int> queue1;

queue<int> queue2;

queue<int> queue3;

我是否创建了一个 for 循环来执行此操作?或者还有其他方法吗?

Do i create a for loop to do this? Or is there another way to do so?

for (int i = 0; i<userInput; i++)
{
   queue<int> queue[i];
}

上面的方法可行吗?基本上问用户他们想要创建多少个队列,它会根据他的输入创建它们.

Would the above work? Basically ask the user how many queues they want created, and it will create them based on his input.

推荐答案

vector<queue<int>> queues(n);

这篇关于一次创建多个队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆