|
From: <or...@vp...> - 2003-01-03 13:27:10
|
Hello everyone!
As far as I know, there is no linked list implementation in the C standard
library. If someone knows of a good implementation of a linked list (sorted or
unsorted), please let me know. (C only)
Although I have made an implementation of it, I don't know what kind of
interface would be good. I have made the following:
This is the header for my "list.h":
typedef int (*compproc)(void*,void*);
typedef struct _node{
void* value;
struct _node *prev;
struct _node *next;
}*pnode;
typedef struct _list{
int length;
pnode first;
pnode last;
compproc cmp; /* if NULL, the list is unsorted */
}*plist;
/* list management */
plist list_create(compproc cmp);
void list_destroy(plist pl);
pnode list_add(plist pl, void* value);
int list_remove(plist pl, pnode pn);
int list_length(plist pl);
/* list utility functions */
pnode list_search(plist pl, void* value);
If one wants to iterate through the list, a simple for will make it:
for(pnode=plist->first;pnode!=NULL;pnode=pnode->next){
...
}
The list is a doubly linked non-circular list (for fast operations).
The list is sorted with the cmp function, specified at the creation of the list.
(the same as the cmp in the qsort() in C) At each list_add() the element will be
automatically inserted sortedly. If NULL is given, the list will be unsorted.
My question is, is this interface is a good one, or should I make changes. The
reason why I want to know this, is because I am making a library, which will
contain this list, and I want to know whether it is useable well?
I will release this list implementation separately (for even you), if you think
it is good enough.
ALL suggestions are welcome. Thank you.
--
Regards
Balázs
|