map<int, Bid*> Auctioneer::compareBidList(map<int, Bid*>& one, map<int, Bid*>& two) // pass references &
{
map<int, Bid*> Sorted;
map<int, Bid*>::iterator iterOne;
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;
}
The call to the function above:
1 2 3 4 5 6 7 8 9
void Auctioneer::displaySorted(map<int, Bid*>& one, map<int, Bid*>& two) {
map<int, Bid*> buyers, sellers,Sorted;
map<int, Bid*>::iterator iter;
compareBidList(buyers,sellers);
cout <<"Sorted bids are ment to be here!\n";
for(iter=Sorted.begin(); iter != Sorted.end(); iter++){
cout << iter->second->toString() << endl<<"\n";}
}
call in main:
// all are declared!
auctioneer.displaySorted(buyers,sellers)