Mam pewien problem zwiazany z obsluga listy, skladajacej sie z 2 pol w strukturze - chcialabym usunac elementy powtarzajace sie [c.unique(op), tylko jakie op?!] i posortowac ją wg wartosci jednego z pol - i nie bardzo mam pomysl jak to zrobic...wiec licze ze ktos mądrzejszy m iz tym pomoże :)
0
0
#include <iostream>
#include <list>
#include <cstdlib>
using namespace std;
struct TElement
{
int pole1, pole2;
/*Operator porownania, uzywany przy sprawdzaniu czy elementy sa takie same*/
bool operator==(const TElement &element) const
{
return (pole2 == element.pole2) && (pole1 == element.pole1);
}
/*Uzywany do ustalenia kolejosci podczas sortowania*/
bool operator<(const TElement &element) const
{
return (element.pole1 == pole1) ? pole2 < element.pole2 :
pole1 < element.pole1;
}
};
int main()
{
const int ILE_ELEMENTOW = 10000;
list <TElement> lista;
for (int i = 0; i < ILE_ELEMENTOW; i++)
{
TElement element= {rand() % 200, rand() % 100};
lista.push_back(element);
}
lista.sort();//posortowanie
lista.unique();//usuniecie powtarzajacych sie
list <TElement>::iterator start = lista.begin(),
stop = lista.end();
while (start != stop)
{
cout << start->pole1 << ", " << start->pole2 << endl;
start ++;
}
cin.get();
return 0;
}