我一直在想如何插入从1到100范围内的50个独特的随机整数。我看了其他例子,但它很难翻译成我使用的代码。请问有人能让我朝着正确的方向改变我的代码太多了吗?如何将唯一随机整数插入链表中?
void displayListForward(SortedListInterface<int>* listPtr)
{
cout << "The sorted list contains " << endl;
for (int pos = 1; pos <= listPtr->getLength(); pos++)
{
cout << listPtr->getEntry(pos) << " ";
}
cout << endl << endl;
}
void InsertRandomInts()
{
LinkedSortedList<int> list;
srand((unsigned)time(NULL));
for (int i = 0; i < 50; ++i)
{
int b = rand() % 100 + 1;
list.insertSorted(b);
displayListForward(&list);
}
}
开始与[组](http://en.cppreference.com/w/cpp/container/set),插入,只要其尺寸小于请求的数值,然后复制到列表中。 –
我不明白。我已经保持我的数值少于我想要的数字。 –
那么你遇到了什么问题? –