If you know that there will always only be two elements then a struct
might be a good idea. Or you can use std::map as Jim Langston suggested
(or std::multimap if the first integer is not always unique).
thanks for your suggestion.
And I try the following code, it also works. Does list::sort
automatically sort on the first element of its element?
#include <list>
#include <vector>
#include <algorithm>
#include <iostream>
typedef std:
air <int, int> Int_Pair;
int main( )
{
std::list <Int_Pair> v1;
std::list <Int_Pair>::iterator Iter;
v1.push_back(Int_Pair(8,4));
v1.push_back(Int_Pair(5,4));
v1.push_back(Int_Pair(3,4));
for ( Iter = v1.begin( ); Iter != v1.end( ); Iter++ )
{
std::cout << (*Iter).first << (*Iter).second << std::endl;
}
std::cout << std::endl;
v1.sort();
for ( Iter = v1.begin( ); Iter != v1.end( ); Iter++ )
{
std::cout << (*Iter).first << (*Iter).second << std::endl;
}
}