mirror of
https://gitlab.com/klmp200/LO27.git
synced 2024-11-05 12:28:03 +00:00
Little fix for lists
This commit is contained in:
parent
c2fbc32f16
commit
27eb6cc460
@ -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;
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
typedef struct ListElement ListElement;
|
||||
struct ListElement {
|
||||
void *data;
|
||||
cellElement *data;
|
||||
ListElement *next;
|
||||
ListElement *previous;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user