sorting lists

deleted
Last edited on
The problem with this approach isn´t the sorting... that part´s easy with std::sort(), the big problem is that you can´t sort one of the lists without messing everything up.

Here´s the solution as I would implement it: Create a structure with the stockName and the price. Then create a list of that structure and sort it.
example:
1
2
3
4
5
6
7
8
9
10
11
12
13
struct Stock
{
  std::string name;
  double price;
  bool operator< (Stock s) { return name[0] < s.name[0]; } // This function will be used in std::sort()
};

std::list<Stock> stock;

// Insert your data here

// Sort the data:
std::sort(stock.begin(), stock.end());
Topic archived. No new replies allowed.