1 /* Martin Asser Hansen (mail@maasha.dk) Copyright (C) 2008 - All right reserved */
3 /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> STRUCTURE DECLARATIONS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
6 /* Singly linked list node. */
9 struct _node_sl *next; /* Pointer to next node - NULL if last. */
10 void *val; /* Pointer to data value. */
13 typedef struct _node_sl node_sl;
15 /* Singly linked list. */
18 node_sl *first; /* Pointer to first node - NULL for empty list. */
21 typedef struct _list_sl list_sl;
23 /* Doubly linked list node. */
26 struct _node_dl *next; /* Pointer to next node - NULL if last. */
27 struct _node_dl *prev; /* Pointer to previous node - NULL if last. */
28 void *val; /* Pointer to data value. */
31 typedef struct _node_dl node_dl;
33 /* Doubly linked list. */
36 node_dl *first; /* Pointer to first node - NULL for empty list. */
37 node_dl *last; /* Pointer to last node - NULL for empty list. */
40 typedef struct _list_dl list_dl;
43 /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> FUNCTION DECLARATIONS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
46 /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> SINGLY LINLED LIST <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
49 /* Initialize a new singly linked list. */
50 list_sl *list_sl_new();
52 /* Initialize a new singly linked list node. */
53 node_sl *node_sl_new();
55 /* Add a new node to the beginning of a singly linked list. */
56 void list_sl_add_beg( list_sl **list_ppt, node_sl **node_ppt );
58 /* Add a new node after a given node of a singly linked list. */
59 void list_sl_add_after( node_sl **node_ppt, node_sl **new_node_ppt );
61 /* Remove the first node of a singly linked list. */
62 void list_sl_remove_beg( list_sl **list_ppt );
64 /* Remove the node next to this one in a singly linked list. */
65 void list_sl_remove_after( node_sl **node_ppt );
67 /* Debug function to print all elements from a singly linked list. */
68 void list_sl_print( list_sl *list_pt );
70 /* Debug funtion to print a singly linked list node. */
71 void node_sl_print( node_sl *node_pt );
73 /* Sort a singly linked list according to the compare function. */
74 void list_sl_sort( list_sl **list_ppt, int ( *compare )( const void *a, const void *b ) );
76 /* Free memory for all nodes in and including the singly linked list. */
77 void list_sl_destroy( list_sl **list_ppt );
79 /* Free memory for singly linked list node and value. */
80 void node_sl_destroy( node_sl **node_ppt );
83 /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DOUBLY LINKED LIST <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
86 /* Initialize a new doubly linked list. */
87 list_dl *list_dl_new();
89 /* Initialize a new doubly linked list node. */
90 node_dl *node_dl_new();
92 /* Add a new node to the beginning of a doubly linked list. */
93 void list_dl_add_beg( list_dl **list_ppt, node_dl **node_ppt );
95 /* Add a new node to the end of a doubly linked list. */
96 void list_dl_add_end( list_dl **list_ppt, node_dl **node_ppt );
98 /* Add a new node before a given node of a doubly linked list. */
99 void list_dl_add_before( list_dl **list_ppt, node_dl **node_ppt, node_dl **new_node_ppt );
101 /* Add a new node after a given node of a doubly linked list. */
102 void list_dl_add_after( list_dl **list_ppt, node_dl **node_ppt, node_dl **new_node_ppt );
104 /* Remove a node from a doubly linked list. */
105 void list_dl_remove( list_dl **list_ppt, node_dl **node_ppt );
107 /* Debug function to print all elements from a doubly linked list. */
108 void list_dl_print( list_dl *list_pt );
110 /* Debug funtion to print a doubly linked list node. */
111 void node_dl_print( node_dl *node_pt );
113 /* Free memory for all nodes in and including the doubly linked list. */
114 void list_dl_destroy( list_dl **list_ppt );
116 /* Free memory for doubly linked list node and value. */
117 void node_dl_destroy( node_dl **node_ppt );
119 /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> GENERIC LINKED LIST <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
122 /* Returns the number of nodes in a linked list. */
123 size_t list_count( void *list_pt );
126 /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ASSORTED SORTING FUNCTIOS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
129 /* Sort in ascending order according to char node values. */
130 int cmp_list_sl_char_asc( const void *a, const void *b );
132 /* Sort in descending order according to char node values. */
133 int cmp_list_sl_char_desc( const void *a, const void *b );
136 /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/