gattrib

listsort.c File Reference

#include <stdio.h>
#include <ctype.h>
#include <libgeda/libgeda.h>
#include "../include/struct.h"
#include "../include/prototype.h"
#include "../include/globals.h"
Include dependency graph for listsort.c:

Go to the source code of this file.

Functions

int cmp (STRING_LIST *al, STRING_LIST *bl)
 Compare values of string data.
STRING_LISTlistsort (STRING_LIST *list, int is_circular, int is_double)
 Sort the linked list.

Detailed Description

Linked list sorting code taken from http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html and hacked to serve in gattrib by SDB.

Definition in file listsort.c.


Function Documentation

int cmp ( STRING_LIST al,
STRING_LIST bl 
)

Comparison function -- compare values of string data.

Parameters:
alpointer to first STRING_LIST item to be compared
blpointer to second STRING_LIST item to be compared
Returns:
+ve if al > bl, -ve if al < bl, 0 if al = bl

Definition at line 87 of file listsort.c.

STRING_LIST* listsort ( STRING_LIST list,
int  is_circular,
int  is_double 
)

This is the actual sort function. Notice that it returns the new head of the list. (It has to, because the head will not generally be the same element after the sort.) So unlike sorting an array, where you can do

  • sort(myarray);

you now have to do

  • list = listsort(mylist);
Parameters:
listThe linked STRING_LIST to be sorted
is_circularTRUE if this is a circularly linked list
is_doubleTRUE if this is a doubly-linked list
Returns:
a pointer to the new head of the list

Definition at line 139 of file listsort.c.

Here is the call graph for this function:

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines