我有一个函数,将随机整数插入到列表中,并显示列表的函数。我现在有什么,有没有办法显示该列表反向?如何反转显示链接列表?
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);
}
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;
}
为了我需要做的事情,我将采取快速解决方案。谢谢。 –