1
0
mirror of https://gitlab.com/klmp200/LO27.git synced 2024-12-23 02:21:08 +00:00

Little fix for lists

This commit is contained in:
Antoine Bartuccio 2016-12-11 01:25:35 +01:00
parent c2fbc32f16
commit 27eb6cc460
2 changed files with 5 additions and 16 deletions

View File

@ -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;

View File

@ -8,7 +8,7 @@
typedef struct ListElement ListElement;
struct ListElement {
void *data;
cellElement *data;
ListElement *next;
ListElement *previous;
};