summaryrefslogtreecommitdiff
path: root/misc.c
diff options
context:
space:
mode:
authorcelestar <celestar@openttd.org>2005-01-29 19:41:44 +0000
committercelestar <celestar@openttd.org>2005-01-29 19:41:44 +0000
commit752b3f0dd614217d68f361e2d0b2cc599a37c860 (patch)
treefcefcecfa2ec7dd8e9178d5206788bd62dcf3c53 /misc.c
parent885fd2b15c1ae9a1422f82b8bcdd9d1a287c3aa6 (diff)
downloadopenttd-752b3f0dd614217d68f361e2d0b2cc599a37c860.tar.xz
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
a single station. Thanks to: Truelight for the saveload code, Darkvater and Hackykid for network testing and Tron for proof-reading 1500 lines of diff.
Diffstat (limited to 'misc.c')
-rw-r--r--misc.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/misc.c b/misc.c
index 1ae7d0f94..1ed230671 100644
--- a/misc.c
+++ b/misc.c
@@ -743,6 +743,35 @@ int FindFirstBit(uint32 value)
return i;
}
+//!We're writing an own sort algorithm here, as
+//!qsort isn't stable
+//!Since the number of elements will be low, a
+//!simple bubble sort will have to do :)
+
+void bubblesort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *))
+{
+ uint i,k;
+ void *buffer = malloc(size);
+ char *start = base;
+
+ nmemb--;
+
+ for (i = 0; i < nmemb; i++) {
+ for (k = 0; k < nmemb; k++) {
+ void *a, *b;
+ a = start + size * k;
+ b = start + size * (k + 1);
+ if (compar(a, b) > 0) {
+ memcpy(buffer, a, size);
+ memcpy(a, b, size);
+ memcpy(b, buffer, size);
+ }
+ }
+ }
+
+ free(buffer);
+ buffer = NULL;
+}
static void Save_NAME(void)
{