I use Qt
and C++
, I have a list (QList<int>)
list<<1<<3<<4<<5<<9<<22<<32<<45
I want to make this
If user enter 4 I want to make this;
list1<<1<<3<<4<<5
list2<<9<<22<<32<<45
If user enter 3, I 开发者_StackOverflowwant to divide 3 lists etc.. How can I do this?
See the code below. I have not tested it , but i might give you an idea. Remember to
#include <QtAlgorithms>
too.
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);
}
精彩评论