summaryrefslogtreecommitdiff
path: root/sorted_list.c
diff options
context:
space:
mode:
authorpdw <>2002-03-24 16:22:26 +0000
committerpdw <>2002-03-24 16:22:26 +0000
commit3004ea063cbb186a63af99a2e13d7cb09f23360d (patch)
treed617af0ad0619334f899d3405350edb9b1b2407b /sorted_list.c
downloadiftop-3004ea063cbb186a63af99a2e13d7cb09f23360d.zip
iftop
Diffstat (limited to 'sorted_list.c')
-rw-r--r--sorted_list.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/sorted_list.c b/sorted_list.c
new file mode 100644
index 0000000..50d0b06
--- /dev/null
+++ b/sorted_list.c
@@ -0,0 +1,59 @@
+/*
+ * sorted_list.c:
+ *
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include "sorted_list.h"
+
+
+void sorted_list_insert(sorted_list_type* list, void* item) {
+ sorted_list_node *node, *p;
+
+ p = &(list->root);
+
+ while(p->next != NULL && list->compare(item, p->next->data) > 0) {
+ p = p->next;
+ }
+
+ node = (sorted_list_node*)malloc(sizeof(sorted_list_node));
+ if(node == NULL) {
+ fprintf(stderr,"Out of memory\n");
+ exit(1);
+ }
+
+ node->next = p->next;
+ node->data = item;
+ p->next = node;
+}
+
+
+sorted_list_node* sorted_list_next_item(sorted_list_type* list, sorted_list_node* prev) {
+ if(prev == NULL) {
+ return list->root.next;
+ }
+ else {
+ return prev->next;
+ }
+}
+
+void sorted_list_destroy(sorted_list_type* list) {
+ sorted_list_node *p, *n;
+ p = list->root.next;
+
+ while(p != NULL) {
+ n = p->next;
+ free(p);
+ p = n;
+ }
+
+ list->root.next = NULL;
+}
+
+void sorted_list_initialise(sorted_list_type* list) {
+ list->root.next = NULL;
+}
+
+
+