]> gitweb.fperrin.net Git - iftop.git/blob - sorted_list.c
Import iftop-1.0pre4
[iftop.git] / sorted_list.c
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