I am trying to match values in map container.Can anyone guide me on this.
This is the function I use for the matching!
values in the map:
Key | trdId | qty | type | price
1 2 10 A 100
2 1 10 B 120
3 2 10 A 100
4 1 12 B 115
Conditions for the matching: price of B > price of A
one type == 'A' while the other is type=='B'
I move the matched bids to another container called Sorted.
I tried as below, but there were no results shown.when I check the Sorted contain for size, it shows its empty.
Code:
map<int, Bid*>bidtable
map<int, Bid*>::const_iterator iter;
map<int, Bid*> Auctioneer::compareBidList(map<int, Bid*>& one, map<int, Bid*>& two) // pass references &
{
map<int, Bid*> Sorted;
map<int, Bid*>::iterator iterOne;
map<int, Bid*>::iterator iterTwo;
for(iterOne = one.begin(); iterOne != one.end(); ++iterOne)
{
if(iterOne->second->bidType == 'A') // select all type A from one
{
map<int, Bid*>::iterator iterTwo;
for(iterTwo = two.begin(); iterTwo != two.end(); ++iterTwo)
{
if(iterTwo->second->bidType == 'B') // select all type B from two
{
if(iterOne->second->price < iterTwo->second->price) // select on price between type A and type B
{
Sorted.insert(*iterOne);
Sorted.insert(*iterTwo);
}
}
}
}
}
return Sorted;
}