Main Page | Modules | Data Structures | File List | Data Fields | Globals

sort.c

Go to the documentation of this file.
00001 /* BeeOS v0.1. Created: 2004/03/10 Modified: 2004/03/10
00002  * Copyright (C) 2004 Paul Harvey - ROMA, Australia.
00003  * csirac@users.sourceforge.net
00004  */
00005 
00006 /*   This program is free software; you can redistribute it and/or modify
00007  *   it under the terms of the GNU General Public License as published by
00008  *   the Free Software Foundation; either version 2 of the License, or
00009  *   (at your option) any later version.
00010  * 
00011  *   This program is distributed in the hope that it will be useful,
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *   GNU General Public License for more details.
00015  * 
00016  *   You should have received a copy of the GNU General Public License
00017  *   along with this program; if not, write to the Free Software
00018  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00024  #include "../include/beeos.h"
00025  #include "../include/bmalloc.h"
00026  #include "../include/bstring.h"
00027 
00036 void bubblesort(char *base, ushort num, ushort size, 
00037     sshort(*cmp_func)(const void *, const void *))
00038 {
00056     char *ptr;
00057     char *temp = bmalloc(size, NULL);
00058     ushort i, j;
00059     
00060     for (i = 0; i < num - 1; i++) {
00061         for (j = 0, ptr = base; j < num - 1 - i; j++, ptr += size) {
00062             if (0 > cmp_func(ptr, ptr + size)) {
00063                 bmemcpy(temp, ptr + size, size);
00064                 bmemcpy(ptr + size, ptr, size);
00065                 bmemcpy(ptr, temp, size);
00066             }
00067         }
00068     }
00069     bfree(temp);
00070     
00071     return;
00072 }

Generated on Sat Apr 10 17:08:02 2004 for BeeOS by doxygen 1.3.6-20040222