Namek91
(Namekxxx)
1 Listopad 2011 18:48
#1
Mam problem z tablicą pairów, którą chcę posortować za pomocą quick sorta. Chodzi o posortowanie tablicy, względem pierwszych elementów, czyli np. na wejściu:
235 3
15 4
42 6
ma dać na wyjściu:
15 4
42 6
235 3
Jeśli chodzi o zwykły quick sort dla normalnej tablicy, to nie ma problemu, chociażby tutaj:
http://webcache.googleusercontent.com/s … pl&strip=1
ale kompletnie nie mam pojęcia, jak posortować quick sortem (koniecznie tą metodą) tablicę pairów.
Proszę o pomoc :).
drobok
(Drobok)
1 Listopad 2011 19:07
#2
(strzelam)Sortujesz tylko first, zmieniając wskaźnik dla następnego przebiegu.
kuhar
(Kubakuderski)
5 Listopad 2011 21:21
#3
Możesz porównywać całe pary ze sobą, nie tylko firsty.
The header also overloads the relational operators ==, <, !=, >, >= and <= , so as to be able to compare pair objects of the same type directly: Two pair objects are compared equal if the first elements in both objects compare equal to each other and both second elements also compare equal to each other - they all have to match. In inequality comparisons (<, >), the first elements are compared first, and only if the inequality comparison is not true for them, the second elements are compared.