diff --git a/LibList/CellElement.c b/LibList/CellElement.c index 7e90729..0ef1521 100644 --- a/LibList/CellElement.c +++ b/LibList/CellElement.c @@ -1,14 +1,122 @@ -/* -* @Author: klmp200 -* @Date: 2016-12-10 01:32:50 -* @Last Modified by: klmp200 -* @Last Modified time: 2016-12-10 04:29:48 -*/ +/*** +--- CellElemFunc --- +---Created by : Naej Doree --- +***/ #include #include #include + +cellElement * CreateCellElem(){ + cellElement * elem = NULL; + elem = (cellElement*) malloc(sizeof(cellElement)); + + if (elem == NULL){ + return NULL; + } + + printf("---Created cellElement---\n"); + + elem->value = true; + elem->nextCol = NULL; + elem->nextRow = NULL; + + + return elem; +} + +void freeCellElem(cellElement * elem){ + free(elem); + elem = NULL; +} + +int AddNextCol(cellElement* tree){ + + cellElement * elem = NULL; + elem = (cellElement*) malloc(sizeof(cellElement)); + + if (elem == NULL){ + return -1; + } + + printf("---insertNextCol---\n"); + + elem->value = true; + elem->nextCol = NULL; + elem->nextRow = NULL; + + if (tree->nextCol == NULL){ + tree->nextCol = elem; + }else{ + return -2; + } + + return 1; +} + + +int AddNextRow(cellElement* tree){ + + cellElement * elem = NULL; + elem = (cellElement*) malloc(sizeof(cellElement)); + + if (elem == NULL){ + return -1; + } + + printf("---insertNextRow---\n"); + + elem->value = true; + elem->nextRow = NULL; + elem->nextRow = NULL; + if (tree->nextRow == NULL){ + tree->nextRow = elem; + }else{ + return -2; + } + return 1; +} + +void removeNextCol(cellElement* tree){ + printf("---removeNextCol---\n"); + + if (tree->nextCol != NULL){ + cellElement * elem = tree->nextCol; + free(elem); + elem = NULL; + tree->nextCol = NULL; + } + +} + +void removeNextRow(cellElement* tree){ + printf("---removeNextRow---\n"); + + if (tree->nextRow != NULL){ + cellElement* elem = tree->nextRow; + free(elem); + elem =NULL; + tree->nextRow = NULL; + } + +} +void recursivePrint(cellElement * tree){ + if (tree != NULL){ + printf("Elem : x: %d y: %d \n",tree->colIndex,tree->rowIndex); + if (tree->nextCol != NULL){ + recursivePrint(tree->nextCol); + } + if (tree->nextRow != NULL){ + recursivePrint(tree->nextRow); + } + if (tree->nextCol == NULL && tree->nextCol == NULL){ + printf("leaf\n"); + } + + } +} + void FreeCellElement(cellElement* element) { if (element != NULL){ free(element); diff --git a/LibList/CellElement.h b/LibList/CellElement.h index be01e3b..688395f 100644 --- a/LibList/CellElement.h +++ b/LibList/CellElement.h @@ -37,8 +37,18 @@ struct cellElement { struct cellElement * nextRow; }; -typedef struct cellElement * cellElement; +typedef struct cellElement cellElement; +cellElement * CreateCellElem(); +void freeCellElem(cellElement * elem); + +int AddNextCol(cellElement* tree); +int AddNextRow(cellElement* tree); + +void removeNextCol(cellElement* list); +void removeNextRow(cellElement* list); + +void recursivePrint(cellElement * tree); void FreeCellElement(cellElement* element); diff --git a/Makefile b/Makefile index d7e22c6..844b9b7 100644 --- a/Makefile +++ b/Makefile @@ -17,15 +17,14 @@ SOURCECFILE=$(SOURCE:=.c) SOURCEOFILE=$(SOURCE:=.o) #Library variables -DEPENDENCE=libCellElement.so -DEPENDENCENAME=CellElement +# DEPENDENCE=libCellElement.so +# DEPENDENCENAME=CellElement DEPENDENCELIST=libList.so DEPENDENCENAMELIST=List all: $(TARGET) - #Generating the main.exe $(TARGET): $(SOURCEOFILE) $(DEPENDENCELIST) lib @echo "\n Generating the " $(TARGET) " binary" @@ -35,7 +34,7 @@ $(TARGET): $(SOURCEOFILE) $(DEPENDENCELIST) lib lib: @echo "\n Generating the automaton library binary" mkdir -p Libs - $(MAKE) -C LibCell + # $(MAKE) -C LibCell $(DEPENDENCELIST): @echo "\n Generating the list library binary" @@ -54,4 +53,3 @@ clean: rm -rf *.o ./Libs/*.so *.exe $(MAKE) -C LibCell clean $(MAKE) -C LibList clean - diff --git a/main.c b/main.c index 32d1521..b1efa8a 100644 --- a/main.c +++ b/main.c @@ -8,9 +8,21 @@ #include #include +#include + +int main(int argc, char **argv){ + cellElement * tree = NULL; + tree = CreateCellElem(); + tree->colIndex = 1; + AddNextRow(tree); + tree->nextRow->colIndex = 2; + AddNextCol(tree); + tree->nextCol->colIndex = 3; + recursivePrint(tree); + removeNextRow(tree); + removeNextCol(tree); + recursivePrint(tree); -int main(int argc, char *argv[]) -{ - printf("Hello World\n"); return 0; + }