diff --git a/LibList/list.c b/LibList/list.c index f422a88..02416f3 100644 --- a/LibList/list.c +++ b/LibList/list.c @@ -30,14 +30,11 @@ List * CreateList() { int unshift(List *list, cellElement *data){ int ok = SUCCESS; - cellElement* newData = (cellElement*) malloc(sizeof(cellElement)); - /* Create a new element */ ListElement *newElement = malloc(sizeof(*newElement)); - if (list != NULL && newElement != NULL && newData != NULL){ - memcpy(newData, data, sizeof(cellElement)); - newElement->data = newData; + if (list != NULL && newElement != NULL){ + newElement->data = data; /* Insert the element at the begining of the list */ @@ -56,9 +53,6 @@ int unshift(List *list, cellElement *data){ if (newElement != NULL){ free(newElement); } - if (newData != NULL){ - free(newData); - } ok = FAILURE; } @@ -67,12 +61,10 @@ int unshift(List *list, cellElement *data){ int push(List *list, cellElement *data){ int ok = SUCCESS; - cellElement *newData = (cellElement*) malloc(sizeof(cellElement)); ListElement *newElement = malloc(sizeof(*newElement)); - if(list != NULL && newElement != NULL && newData != NULL){ - memcpy(newData, data, sizeof(cellElement)); - newElement->data = newData; + if(list != NULL && newElement != NULL){ + newElement->data = data; newElement->next = NULL; if (list->tail == NULL){ list->tail = newElement; @@ -88,9 +80,6 @@ int push(List *list, cellElement *data){ if (newElement != NULL){ free(newElement); } - if (newData != NULL){ - free(newData); - } ok = FAILURE; } return ok; diff --git a/LibList/list.h b/LibList/list.h index 455c941..b1d61ee 100644 --- a/LibList/list.h +++ b/LibList/list.h @@ -8,7 +8,7 @@ typedef struct ListElement ListElement; struct ListElement { - void *data; + cellElement *data; ListElement *next; ListElement *previous; };