1
0
mirror of https://gitlab.com/klmp200/LO27.git synced 2024-11-22 21:03:20 +00:00

Merge branch 'sli' into 'master'

Little fix for lists

See merge request !4
This commit is contained in:
Antoine Bartuccio 2016-12-11 00:27:00 +00:00
commit ea0cb5d10d
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;
};