1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
//Function that does the compare!
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;
}
map<int, Bid*> Auctioneer::show(map<int, Bid*>& one, map<int, Bid*>& two) {
map<int, Bid*> Sorted;
map<int, Bid*>::iterator iterOne;
map<int, Bid*>::iterator iterTwo;
cout << "-----------------The sorted List-------------------------";
for(iterOne=Sorted.begin(); iterOne!= Sorted.end(); iterOne++){
cout << iterOne->second->toString() << endl<<"\n";}
for(iterTwo=Sorted.begin(); iterTwo!= Sorted.end(); iterTwo){
cout << iterTwo->second->toString() << endl<<"\n";}
}
//my call in the main after declaration was as follows
map<int, Bid*> buyers, sellers;
auctioneer.compare(sellers,buyers);
show("Bids after sorting:", sellers);
show(buyers);
| |