diff --git a/LibAutomaton/CellElement.c b/LibAutomaton/CellElement.c index 1c974ad..480513f 100644 --- a/LibAutomaton/CellElement.c +++ b/LibAutomaton/CellElement.c @@ -31,21 +31,17 @@ bool is_leaf(cellElement* tree){ } } -int AddNextCol(cellElement* tree){ - - cellElement * elem = NULL; - elem = (cellElement*) malloc(sizeof(cellElement)); - - if (elem == NULL){ +int SetPositionIndex(cellElement* elem,int Col,int Row){ + if (elem != NULL){ + elem->colIndex = Col; + elem->rowIndex = Row; + } else { return -1; } + return 1; +} - printf("---insertNextCol---\n"); - - elem->value = true; - elem->nextCol = NULL; - elem->nextRow = NULL; - +int SetNextCol(cellElement* tree,cellElement* elem){ if (tree->nextCol == NULL){ tree->nextCol = elem; }else{ @@ -54,11 +50,35 @@ int AddNextCol(cellElement* tree){ return 1; } +int SetNextRow(cellElement* tree,cellElement* elem){ + if (tree->nextRow == NULL){ + tree->nextRow = elem; + }else{ + return -2; + } + return 1; +} + +int AddNextCol(cellElement* tree){ + + cellElement * elem = NULL; + elem = CreateCellElem(); + + if (elem == NULL){ + return -1; + } + + printf("---insertNextCol---\n"); + + + return(SetNextCol(tree,elem)); +} + int AddNextRow(cellElement* tree){ cellElement * elem = NULL; - elem = (cellElement*) malloc(sizeof(cellElement)); + elem = CreateCellElem(); if (elem == NULL){ return -1; @@ -66,15 +86,7 @@ int AddNextRow(cellElement* tree){ printf("---insertNextRow---\n"); - elem->value = true; - elem->nextRow = NULL; - elem->nextCol = NULL; - if (tree->nextRow == NULL){ - tree->nextRow = elem; - }else{ - return -2; - } - return 1; + return(SetNextRow(tree,elem)); } void removeNextCol(cellElement* tree){