STL List Sorting
That won't let you sort by a different value.
You need to use a lambda or a functor like in my original example, except instead of std::sort you use transaction.sort.
http://www.cplusplus.com/reference/list/list/sort/
1 2 3 4 5 6 7 8 9
|
struct TransactionPriceComparator
{
bool operator()(const WHMgmtDetails &a, const WHMgmtDetails &b)
{
return a.unitPrice < b.unitPrice;
}
};
transaction.sort(TransactionPriceComparator());
|
1 2 3 4 5 6 7 8 9
|
struct TransactionQuantityComparator
{
bool operator()(const WHMgmtDetails &a, const WHMgmtDetails &b)
{
return a.qty < b.qty;
}
};
transaction.sort(TransactionQuantityComparator());
|
...
Topic archived. No new replies allowed.