0
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
using namespace std;

struct stock{
    int numOrder, numStock, price;
};

list <stock> Stock[5][2];
vector <int> Price[5]; int bestPrice[5] = {0, };

bool cmp1(const stock &a, const stock &b){
    if(a.price < b.price) return true;
    else if(a.price == b.price){
        if(a.numOrder < b.numOrder) return true;
    }
    return false;
}

int buy(int mNumber, int mStock, int mQuantity, int mPrice)
{
    mStock--; 

    sort(Stock[mStock][1].begin(), Stock[mStock][1].end(), cmp1);

    return 0;
}

And compile error message is this:

/opt/gcc10/gcc-10.3.0/include/c++/10.3.0/bits/stl_algo.h:1980:22: error: no match for ‘operator-’ (operand types are ‘std::_List_iterator<stock>’ and ‘std::_List_iterator<stock>’)

but I don't know how to correct it.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
sen
  • 1
  • 2
  • 3
    `std::sort` is unable to sort list items, since `std::list` is unable to provide random access to its items. Thus, it has own method [`std::list::sort()`](https://en.cppreference.com/w/cpp/container/list/sort) that should be used for sorting list items. – 273K Jan 11 '22 at 06:37
  • @273K thank you so much i love you – sen Jan 11 '22 at 06:42
  • Or just change `std::list` to `std::vector`, there are very few cases where a linked list is useful – Alan Birtles Jan 11 '22 at 07:26

0 Answers0