diff options
author | Klaus Schmidinger <vdr@tvdr.de> | 2004-11-01 10:40:38 +0100 |
---|---|---|
committer | Klaus Schmidinger <vdr@tvdr.de> | 2004-11-01 10:40:38 +0100 |
commit | 0b62aff0e3385ed0c11fda145c2a5167bbc1c56d (patch) | |
tree | 6067296e3f76b842a59919c3453a45c83538ad97 /tools.c | |
parent | c88e65b6385a9c72778ea46fe4c4c805976c7b96 (diff) | |
download | vdr-0b62aff0e3385ed0c11fda145c2a5167bbc1c56d.tar.gz vdr-0b62aff0e3385ed0c11fda145c2a5167bbc1c56d.tar.bz2 |
Now using qsort() to sort cListBase lists
Diffstat (limited to 'tools.c')
-rw-r--r-- | tools.c | 35 |
1 files changed, 22 insertions, 13 deletions
@@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: tools.c 1.80 2004/06/13 14:36:41 kls Exp $ + * $Id: tools.c 1.81 2004/10/31 16:42:36 kls Exp $ */ #include "tools.h" @@ -939,19 +939,28 @@ int cListBase::Count(void) const return n; } +static int CompareListObjects(const void *a, const void *b) +{ + const cListObject *la = *(const cListObject **)a; + const cListObject *lb = *(const cListObject **)b; + return la->Compare(*lb); +} + void cListBase::Sort(void) { - bool swapped; - do { - swapped = false; - cListObject *object = objects; - while (object) { - if (object->Next() && *object->Next() < *object) { - Move(object->Next(), object); - swapped = true; - } - object = object->Next(); - } - } while (swapped); + int n = Count(); + cListObject *a[n]; + cListObject *object = objects; + int i = 0; + while (object && i < n) { + a[i++] = object; + object = object->Next(); + } + qsort(a, n, sizeof(cListObject *), CompareListObjects); + objects = lastObject = NULL; + for (i = 0; i < n; i++) { + a[i]->Unlink(); + Add(a[i]); + } } |