mirror of
https://gitlab.com/klmp200/LO27.git
synced 2024-11-22 21:43:19 +00:00
Merge branch 'sli' into 'master'
Little fix for lists See merge request !4
This commit is contained in:
commit
ea0cb5d10d
@ -30,14 +30,11 @@ List * CreateList() {
|
|||||||
int unshift(List *list, cellElement *data){
|
int unshift(List *list, cellElement *data){
|
||||||
int ok = SUCCESS;
|
int ok = SUCCESS;
|
||||||
|
|
||||||
cellElement* newData = (cellElement*) malloc(sizeof(cellElement));
|
|
||||||
|
|
||||||
/* Create a new element */
|
/* Create a new element */
|
||||||
|
|
||||||
ListElement *newElement = malloc(sizeof(*newElement));
|
ListElement *newElement = malloc(sizeof(*newElement));
|
||||||
if (list != NULL && newElement != NULL && newData != NULL){
|
if (list != NULL && newElement != NULL){
|
||||||
memcpy(newData, data, sizeof(cellElement));
|
newElement->data = data;
|
||||||
newElement->data = newData;
|
|
||||||
|
|
||||||
/* Insert the element at the begining of the list */
|
/* Insert the element at the begining of the list */
|
||||||
|
|
||||||
@ -56,9 +53,6 @@ int unshift(List *list, cellElement *data){
|
|||||||
if (newElement != NULL){
|
if (newElement != NULL){
|
||||||
free(newElement);
|
free(newElement);
|
||||||
}
|
}
|
||||||
if (newData != NULL){
|
|
||||||
free(newData);
|
|
||||||
}
|
|
||||||
ok = FAILURE;
|
ok = FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,12 +61,10 @@ int unshift(List *list, cellElement *data){
|
|||||||
|
|
||||||
int push(List *list, cellElement *data){
|
int push(List *list, cellElement *data){
|
||||||
int ok = SUCCESS;
|
int ok = SUCCESS;
|
||||||
cellElement *newData = (cellElement*) malloc(sizeof(cellElement));
|
|
||||||
|
|
||||||
ListElement *newElement = malloc(sizeof(*newElement));
|
ListElement *newElement = malloc(sizeof(*newElement));
|
||||||
if(list != NULL && newElement != NULL && newData != NULL){
|
if(list != NULL && newElement != NULL){
|
||||||
memcpy(newData, data, sizeof(cellElement));
|
newElement->data = data;
|
||||||
newElement->data = newData;
|
|
||||||
newElement->next = NULL;
|
newElement->next = NULL;
|
||||||
if (list->tail == NULL){
|
if (list->tail == NULL){
|
||||||
list->tail = newElement;
|
list->tail = newElement;
|
||||||
@ -88,9 +80,6 @@ int push(List *list, cellElement *data){
|
|||||||
if (newElement != NULL){
|
if (newElement != NULL){
|
||||||
free(newElement);
|
free(newElement);
|
||||||
}
|
}
|
||||||
if (newData != NULL){
|
|
||||||
free(newData);
|
|
||||||
}
|
|
||||||
ok = FAILURE;
|
ok = FAILURE;
|
||||||
}
|
}
|
||||||
return ok;
|
return ok;
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
typedef struct ListElement ListElement;
|
typedef struct ListElement ListElement;
|
||||||
struct ListElement {
|
struct ListElement {
|
||||||
void *data;
|
cellElement *data;
|
||||||
ListElement *next;
|
ListElement *next;
|
||||||
ListElement *previous;
|
ListElement *previous;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user