我一直在想如何插入從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),插入,只要其尺寸小於請求的數值,然後複製到列表中。 –
我不明白。我已經保持我的數值少於我想要的數字。 –
那麼你遇到了什麼問題? –