void removeLastList(ListPtr listp){ /* Removes 1 Node from the Start of the List */ if(listp->items > 0){ if(listp->items == 1){ popList(listp); } else{ listp->Current = listp->Last->previous; if(listp->Last != NULL){ listp->destroyNode(&(listp->Last->data)); free(listp->Last); (listp->items)--; } listp->Last = listp->Current; listp->Last->next = (Node*) NULL; } } }
void popList(ListPtr listp){ /* Removes 1 Node from the End of the List */ if(listp->items > 0){ listp->Current = listp->Head; listp->Head = listp->Head->next; /* Make Head point to its next and make the previous of new Head be NULL */ if(listp->Head != NULL) listp->Head->previous = (Node*) NULL; if(listp->Current != NULL){ listp->destroyNode(&(listp->Current->data)); free(listp->Current); (listp->items)--; } listp->Current = listp->Head; } }
void removeCurrentNode(ListPtr listp){ /* Removes the Node Current points to */ Node* temp; if(listp->items > 0){ if(listp->items == 1){ popList(listp); } else{ if(listp->Current == listp->Last){ removeLastList(listp); } else{ if(listp->Current != NULL){ listp->destroyNode(&(listp->Current->data)); temp = listp->Current->next; listp->Current->previous->next = listp->Current->next; /* Make the previous of the Current have as next the next of Current and vice versa */ listp->Current->next->previous = listp->Current->previous; free(listp->Current); listp->Current = temp; (listp->items)--; //TODO: TEST AND FIX MIDDLE } } } } }