int addMiddleList(ListPtr listp,NodePtr position,void* data){ /* Add new Node in the middle of the Queue */ int i=0; //there is always a previous and a next Node if(listp->items > 0){ if(position == NULL) { printf("Position not valid...\n"); return -1; } else { listp->Current = position->previous; //Current is the previous Node } listp->Current->next = malloc(sizeof(Node)); listp->Current->next->previous = listp->Current; listp->Current->next->next = position; position->previous = listp->Current->next; listp->allocateNode(&(listp->Current->next->data),data); listp->Current = listp->Head; (listp->items)++; } else{ printf("List is not properly initialised...\n"); return -1; } }
int addLastList(ListPtr listp,void* data){ /* Adds a Node to the end of the List */ int i=0; if(listp->items == 0){ /* No items yet */ listp->Head = malloc(sizeof(Node)); listp->allocateNode(&(listp->Head->data),data); listp->Head->next = (Node*) NULL; listp->Head->previous = (Node*) NULL; listp->Current = listp->Head; listp->Last = listp->Head; (listp->items)++; return 0; } else if(listp->items > 0){ listp->Last->next = malloc(sizeof(Node)); listp->Last->next->previous = listp->Last; listp->Last = listp->Last->next; listp->Last->next = (Node*) NULL; listp->allocateNode(&(listp->Last->data),data); (listp->items)++; listp->Current = listp->Last; return 0; } else{ printf("List is not properly initialised...\n"); return -1; } }
int addFirstList(ListPtr listp,void* data){ /* Add new Node as Head of the Queue */ int i=0; if(listp->items == 0){ listp->Head = malloc(sizeof(Node)); listp->allocateNode(&(listp->Head->data),data); listp->Head->next = (Node*) NULL; listp->Head->previous = (Node*) NULL; listp->Current = listp->Head; listp->Last = listp->Head; (listp->items)++; return 0; } else if(listp->items > 0){ listp->Head->previous = malloc(sizeof(Node)); listp->Head->previous->next = listp->Head; listp->Head = listp->Head->previous; listp->allocateNode(&(listp->Head->data),data); listp->Head->previous = (Node*) NULL; listp->Current = listp->Head; (listp->items)++; } else{ printf("List is not properly initialised...\n"); return -1; } }