R
rockdale
Hi, all:
I have a std::vector which contains my struct. The data in the vector
is inserted from a std::map, then I will need to sort the vector based
on some criteria and then get the sorted data out. my struct is like:
struct item
{
int itemtypeid;
int itemid;
};
typedef std::deque<item> ItemList;
struct order
{
int orderid;
int ordertypeid;
ItemList itemdata;
};
typedef std::vector<order> VectorOrder;
I use a functor to do the sort by orderid
this is the functor:
class COrderSorter
{
public:
bool operator()(const order& lhs, const order& rhs)
{
return lhs.orderid < rhs.order;
}
};
VectorOrder m_vecOrder
std::sort(m_vecOrder.begin(), m_vecOrder.end(), COrderSorter());
NOW, I need to sort the order by the its item first by itemtypeid,
then by itemid.
for example:
orderid itemtypeid itemid
1 2 4
1 2 3
1 1 5
2 1 2
the final result I need to get:
orderid itemtypeid itemid
2 1 2
1 1 5
1 2 3
1 2 4
Is there a way to achieve this other than the plain iterate through
every order and then iterate through its item?
What the efficient, memory consideration about this?
thanks in advance
-rockdale
I have a std::vector which contains my struct. The data in the vector
is inserted from a std::map, then I will need to sort the vector based
on some criteria and then get the sorted data out. my struct is like:
struct item
{
int itemtypeid;
int itemid;
};
typedef std::deque<item> ItemList;
struct order
{
int orderid;
int ordertypeid;
ItemList itemdata;
};
typedef std::vector<order> VectorOrder;
I use a functor to do the sort by orderid
this is the functor:
class COrderSorter
{
public:
bool operator()(const order& lhs, const order& rhs)
{
return lhs.orderid < rhs.order;
}
};
VectorOrder m_vecOrder
std::sort(m_vecOrder.begin(), m_vecOrder.end(), COrderSorter());
NOW, I need to sort the order by the its item first by itemtypeid,
then by itemid.
for example:
orderid itemtypeid itemid
1 2 4
1 2 3
1 1 5
2 1 2
the final result I need to get:
orderid itemtypeid itemid
2 1 2
1 1 5
1 2 3
1 2 4
Is there a way to achieve this other than the plain iterate through
every order and then iterate through its item?
What the efficient, memory consideration about this?
thanks in advance
-rockdale