dlist.c

Go to the documentation of this file.
00001 /*  Copyright (c) 2006-2007, Philip Busch <broesel@studcs.uni-sb.de>
00002  *  All rights reserved.
00003  *
00004  *  Redistribution and use in source and binary forms, with or without
00005  *  modification, are permitted provided that the following conditions are met:
00006  *
00007  *   - Redistributions of source code must retain the above copyright notice,
00008  *     this list of conditions and the following disclaimer.
00009  *   - Redistributions in binary form must reproduce the above copyright
00010  *     notice, this list of conditions and the following disclaimer in the
00011  *     documentation and/or other materials provided with the distribution.
00012  *   - Neither the name of the author nor the names of its contributors may
00013  *     be used to endorse or promote products derived from this software
00014  *     without specific prior written permission.
00015  *
00016  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00019  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00020  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00021  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00022  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00023  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00024  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00025  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00026  *  POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00029 #include <stdio.h>
00030 #include <stdlib.h>
00031 #include <assert.h>
00032 #include <string.h>
00033 #include "dlist.h"
00034 
00035 
00056 int list_push(node_l **_x, void *_data)
00057 {
00058         node_l *n = NULL;
00059 
00060         assert(_x != NULL);
00061 
00062         if((n = (node_l *)malloc(sizeof(node_l))) == NULL) {
00063                 return(-1);
00064         } else {
00065                 n->data = _data;
00066                 n->next = *_x;
00067 
00068                 *_x = n;
00069                 return(0);
00070         }
00071 }
00072 
00195 /* hare and tortoise approach / classic Floyd’s Cycle Finding Algorithm */
00196 
00299 /* auxiliary function to create a short list */
00300 
00311 /* auxiliary function for testing list_sort() */
00312 int cmp(void *_a, void *_b)
00313 {
00314         data *a = (data *)_a, *b = (data *)_b;
00315 
00316         if(a->n < b->n) return(-1);
00317         if(a->n > b->n) return(1);
00318         return(0);
00319 }
00320 

Generated on Thu Jul 19 13:36:09 2007 for libv by  doxygen 1.5.1-p1. Thank you, SourceForge.net Logo