Hello,
I have a circular list with items added to it and I want to create a function to go through the list to check if an item exists.
Printing my list function
Code:
void show_int( any d ){
printf("%3i", *(int *)d);
}
void show_list(clist * cl, char * caption) {
any d;
printf("\nCAPTION: \"%s\"",caption);
printf("\n clist_size: %3i", clist_size(cl));
printf("\n clist_isempty: %3i", clist_isempty(cl));
printf("\n clist_cursor_inlist: %3i", clist_cursor_inlist(cl));
printf("\n item at cursor: ");
d = clist_get_item(cl);
if (d==NULL)
printf(" NULL");
else
show_int( d );
printf("\n clist_print: \n");
clist_print(cl, &show_int);
NEWLINE
}
Main code
Code:
int a; clist *xs;
int i, d[MAX_INTS];
for (i=0;i<MAX_INTS;i++) d[i]=i;
xs = new_clist();
clist_ins_before( xs, &d[1] );
clist_ins_before( xs, &d[2] );
clist_ins_before( xs, &d[3] );
clist_ins_before( xs, &d[4] );
clist_ins_before( xs, &d[5] );
clist_ins_before( xs, &d[6] );
NEWLINE
show_list(xs, "Test"); // print out the empty list
NEWLINE
I have included "clists.c" where it calls the functions in my main.
I have functions that finds if any of the items in the list are even numbers but I want to be able to call it like this
clist_find(xs, 10); and then it will find any occurrences of 10 in the list.
Here is the code for clist_find - It takes in a pointer to my clist and the function "even"
Code:
int clist_find(clist *c, pred p){
assert(c!=NULL);
clist_goto_head(c);
while (clist_cursor_inlist(c) && (!p(c->cursor->item)))
clist_goto_next(c);
return clist_cursor_inlist(c);
}
I've been trying to figure this out for hours