我使用Qt
and C++
,我有一个列表 (QList<int>)
list<<1<<3<<4<<5<<9<<22<<32<<45
我想做这个
如果用户输入 4 我想做这个;
list1<<1<<3<<4<<5
list2<<9<<22<<32<<45
如果用户输入 3,我想划分 3 个列表等。我该怎么做?
请参阅下面的代码。我没有测试过,但我可能会给你一个想法。记得
#include <QtAlgorithms>
也要。
read x;
QVector<QList<QString> > vectorOfLists;
bool continueLoop = true;
while (continueLoop)
{
QList<QString> temp(x);
if (list.count () > x)
{
qCopy(list.begin(), list.begin()+x, temp.begin());
list.erase (list.begin(), list.begin()+x);
}
else
{
qCopy(list.begin(), list.end(), temp.begin());
continueLoop = false;
}
//Add list to collection
vectorOfLists.append (temp);
}