"Fossies" - the Fresh Open Source Software Archive

Member "g3data-1.5.4/g3data/sort.c" (8 Jan 2011, 3174 Bytes) of package /linux/privat/old/g3data-1.5.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "sort.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2                                                                                                                                                                     
    3 g3data : A program for grabbing data from scanned graphs
    4 Copyright (C) 2000 Jonas Frantz
    5                                                                                                                                                                     
    6     This file is part of g3data.
    7                                                                                                                                                                     
    8     g3data is free software; you can redistribute it and/or modify
    9     it under the terms of the GNU General Public License as published by
   10     the Free Software Foundation; either version 2 of the License, or
   11     (at your option) any later version.
   12                                                                                                                                                                     
   13     g3data is distributed in the hope that it will be useful,
   14     but WITHOUT ANY WARRANTY; without even the implied warranty of
   15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   16     GNU General Public License for more details.
   17                                                                                                                                                                     
   18     You should have received a copy of the GNU General Public License
   19     along with this program; if not, write to the Free Software
   20     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   21                                                                                                                                                                     
   22                                                                                                                                                                     
   23 Authors email : jonas.frantz@welho.com
   24                                                                                                                                                                     
   25 */
   26 
   27 #include <gtk/gtk.h>
   28 #include <stdlib.h>
   29 #include "main.h"
   30 #include "sort.h"
   31 
   32 static gint compare_x(const void *a, const void *b);
   33 static gint compare_y(const void *a, const void *b);
   34 
   35 
   36 static gint compare_x(const void *a, const void *b)
   37 {
   38     const struct PointValue *da = (const struct PointValue *) a;
   39     const struct PointValue *db = (const struct PointValue *) b;
   40     
   41     return (da->Xv > db->Xv) - (da->Xv < db->Xv);
   42 }
   43 
   44 
   45 static gint compare_y(const void *a, const void *b)
   46 {
   47     const struct PointValue *da = (const struct PointValue *) a;
   48     const struct PointValue *db = (const struct PointValue *) b;
   49     
   50     return (da->Yv > db->Yv) - (da->Yv < db->Yv);
   51 }
   52 
   53 
   54 void Order(struct PointValue *RealPos, gint count, gint ordering)
   55 {
   56     /* Sort by x-values */
   57     if (ordering == 1) {
   58         qsort(RealPos, count, sizeof (struct PointValue), compare_x);
   59     } else {
   60     /* Sort by y-values */
   61         qsort(RealPos, count, sizeof (struct PointValue), compare_y);
   62     }
   63 }