Linked lists
Notes
struct listnode {
int data;
struct listnode* next;
};
struct listset {
struct listnode* head;
int bound;
};
/* _________________
| _______ |
| head | NULL | |
| |_______| |
| _______ |
| bound | bound | |
| | param | |
| |_______| |
|_________________|
*/
struct listset* listset_new (int bound)
{
struct list_set* result;
result = malloc(sizeof(struct list_set));
result->bound = bound;
result->head = NULL;
return result;
}
int listset_lookup (struct listset* this, int item)
{
struct listnode* p;
if (item > this->bound || item < 0) return -1;
for (p = this->head; p->next != NULL; p = p->next) {
if (item == p->data) return 1;
}
p = p->next;
return 0;
}