64,651
社区成员
发帖
与我相关
我的任务
分享
#include <LIST>
#include <IOSTREAM>
using namespace std;
void PrintListContents(const list <int>& listInput);
void PrintListContents(const list <int>& listInput)
{
if (listInput.size() > 0)
{
//Write valuse to the screen...
cout << "{ ";
std::list <int> ::const_iterator ielementLocator;
for(ielementLocator = listInput.begin();
ielementLocator != listInput.end();
ielementLocator++)
{
cout << *ielementLocator << " ";
}
cout << "}" << endl << endl;
}
else
cout << "List is empty!" << endl;
}
bool SortPredicate_Descending(const int& lsh, const int& rsh);
bool SortPredicate_Descending(const int& lsh, const int& rsh)
{
return(rsh < lsh);
}
int main(void)
{
std::list <int> listIntegers;
//Insert elements at the begining...
listIntegers.push_front(444);
listIntegers.push_front(300);
listIntegers.push_front(21111);
listIntegers.push_front(-1);
listIntegers.push_front(0);
//Insert an element at the end...
listIntegers.push_back(-5);
cout << "Initial contents of the list are - " << endl;
PrintListContents(listIntegers);
listIntegers.sort();
cout << "Order of elements after sort(): " << endl;
PrintListContents(listIntegers);
listIntegers.sort(SortPredicate_Descending);
cout << "Order of elements after sort() with a predicate: " << endl;
PrintListContents(listIntegers);
return 0;
}
listIntegers.sort(SortPredicate_Descending);
中的SortPredicate_Descending没有参数,这是错误吗?