File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / iftop / sorted_list.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue Feb 21 16:57:34 2012 UTC (12 years, 3 months ago) by misho
Branches: iftop, MAIN
CVS tags: v1_0rc4, v0_17p0, v0_17, HEAD
iftop

    1: /*
    2:  * sorted_list.c:
    3:  *
    4:  */
    5: 
    6: #include <stdlib.h>
    7: #include <stdio.h>
    8: #include "sorted_list.h"
    9: #include "iftop.h"
   10: 
   11: 
   12: void sorted_list_insert(sorted_list_type* list, void* item) {
   13:     sorted_list_node *node, *p;
   14: 
   15:     p = &(list->root);
   16: 
   17:     while(p->next != NULL && list->compare(item, p->next->data) > 0) {
   18:         p = p->next;
   19:     } 
   20: 
   21:     node = xmalloc(sizeof *node);
   22: 
   23:     node->next = p->next;
   24:     node->data = item;
   25:     p->next = node;
   26: }
   27: 
   28: 
   29: sorted_list_node* sorted_list_next_item(sorted_list_type* list, sorted_list_node* prev) {
   30:     if(prev == NULL) {
   31:         return list->root.next;
   32:     }
   33:     else {
   34:         return prev->next;
   35:     }
   36: }
   37: 
   38: void sorted_list_destroy(sorted_list_type* list) {
   39:     sorted_list_node *p, *n;
   40:     p = list->root.next;
   41: 
   42:     while(p != NULL) {
   43:         n = p->next;
   44:         free(p);
   45:         p = n;
   46:     }
   47: 
   48:     list->root.next = NULL;
   49: }
   50: 
   51: void sorted_list_initialise(sorted_list_type* list) {
   52:     list->root.next = NULL;
   53: }
   54: 
   55: 
   56: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>