Still can't get it to work
Then you've done something wrong, and you didn't post enough for me to guess what that might be.
*shrug*
Pick an order and figure out what you need to do to fix your problem.
[Edit]
Removed a few lines I had added to test the other sort order.
[/Edit]
Soma
Code:
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>
typedef std::pair<int, std::pair<int, int> > QueueItem;
struct SorterOne
{
bool operator ()
(
const QueueItem & fLHS
, const QueueItem & fRHS
)
{
return(fLHS.second < fRHS.second);
}
};
struct SorterTwo
{
bool operator ()
(
const QueueItem & fLHS
, const QueueItem & fRHS
)
{
if(fLHS.second.first == fRHS.second.first)
{
return(fLHS.second.second > fRHS.second.second);
}
else
{
return(fLHS.second.first < fRHS.second.first);
}
}
};
template
<
typename FQueue
>
void Build
(
FQueue & fData
)
{
using namespace std;
int lStamp(0);
fData.push(make_pair(0, make_pair(3, ++lStamp)));
fData.push(make_pair(1, make_pair(1, ++lStamp)));
fData.push(make_pair(2, make_pair(1, ++lStamp)));
fData.push(make_pair(3, make_pair(3, ++lStamp)));
fData.push(make_pair(4, make_pair(3, ++lStamp)));
fData.push(make_pair(5, make_pair(3, ++lStamp)));
fData.push(make_pair(6, make_pair(2, ++lStamp)));
fData.push(make_pair(7, make_pair(2, ++lStamp)));
}
template
<
typename FQueue
>
void Dump
(
FQueue & fData
)
{
using namespace std;
while(!fData.empty())
{
const QueueItem & lTop(fData.top());
cout << lTop.first << ':' << '(' << lTop.second.first << ',' << lTop.second.second << ')' << '\n';
fData.pop();
}
}
int main
(
int argc
, char ** argv
)
{
using namespace std;
if((2 == argc) && string("one") == argv[1])
{
priority_queue<QueueItem, vector<QueueItem>, SorterOne> lData;
Build(lData);
Dump(lData);
}
else if((2 == argc) && string("two") == argv[1])
{
priority_queue<QueueItem, vector<QueueItem>, SorterTwo> lData;
Build(lData);
Dump(lData);
}
else
{
priority_queue<QueueItem> lData;
Build(lData);
Dump(lData);
}
return(0);
}