# HG changeset patch # User Eris Caffee # Date 1293821266 21600 # Node ID c6e3398465272ee47f84333d0bbce91963069804 # Parent 112164f48f30e215795e9c6398d4522cfa85b6b3 Rewrote ll_next and ll_prev to fix bug and implement NULL return when end of list is reached. diff -r 112164f48f30 -r c6e339846527 src/LinkedList.c --- a/src/LinkedList.c Wed Dec 29 02:44:09 2010 -0600 +++ b/src/LinkedList.c Fri Dec 31 12:47:46 2010 -0600 @@ -236,36 +236,37 @@ /******************************************************************************* - * Select the next element in the list if there is one. - * Return data pointer of new current element, or NULL is list is empty. + * Return NULL if the list is empty or we are already at the tail, otherwise + * set Curr to the next element and return its data pointer. */ void * ll_next(LinkedList * this) { if (!this) return NULL; - if (this->Curr->next) + if (this->Curr && this->Curr->next) + { this->Curr = this->Curr->next; - - if (this->Curr) return this->Curr->data; + } else return NULL; + } /******************************************************************************* - * Select previous element in the list if there is one. - * Return data pointer of new current element, or NULL is list is empty. + * Return NULL if the list is empty or we are already at the head, otherwise + * set Curr to the prev element and return its data pointer. */ void * ll_prev(LinkedList * this) { if (!this) return NULL; - if (this->Curr->prev) + if (this->Curr && this->Curr->prev) + { this->Curr = this->Curr->prev; - - if (this->Curr) return this->Curr->data; + } else return NULL; } diff -r 112164f48f30 -r c6e339846527 src/main.c --- a/src/main.c Wed Dec 29 02:44:09 2010 -0600 +++ b/src/main.c Fri Dec 31 12:47:46 2010 -0600 @@ -162,10 +162,30 @@ *p_int = 23; ll_push(list3, p_int); - printf("\n\nlist3: "); - for (i=0, size=ll_size(list3); i