diff --git a/CellElemFunc.c b/CellElemFunc.c index 9032683..39105d0 100644 --- a/CellElemFunc.c +++ b/CellElemFunc.c @@ -8,14 +8,50 @@ #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); + + + return 0; } +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; + cellElement * elem = NULL; elem = (cellElement*) malloc(sizeof(cellElement)); if (elem == NULL){ @@ -27,19 +63,20 @@ int AddNextCol(cellElement* tree){ elem->value = true; elem->nextCol = NULL; elem->nextRow = NULL; + if (tree->nextCol == NULL){ tree->nextCol = elem; - return 1; }else{ return -2; } - + + return 1; } int AddNextRow(cellElement* tree){ - cellElement elem = NULL; + cellElement * elem = NULL; elem = (cellElement*) malloc(sizeof(cellElement)); if (elem == NULL){ @@ -53,19 +90,20 @@ int AddNextRow(cellElement* tree){ elem->nextRow = NULL; if (tree->nextRow == NULL){ tree->nextRow = elem; - return 1; }else{ return -2; } + return 1; } void removeNextCol(cellElement* tree){ printf("---removeNextCol---\n"); if (tree->nextCol != NULL){ - DLinkedListElement* elem = tree->nextCol; + cellElement * elem = tree->nextCol; free(elem); - elem =NULL; + elem = NULL; + tree->nextCol = NULL; } @@ -75,9 +113,10 @@ void removeNextRow(cellElement* tree){ printf("---removeNextRow---\n"); if (tree->nextRow != NULL){ - DLinkedListElement* elem = tree->nextRow; + cellElement* elem = tree->nextRow; free(elem); elem =NULL; + tree->nextRow = NULL; } @@ -85,11 +124,13 @@ void removeNextRow(cellElement* tree){ void recursivePrint(cellElement * tree){ if (tree != NULL){ printf("Elem : x: %d y: %d \n",tree->colIndex,tree->rowIndex); - if (tree->nextCol != NUll){ + if (tree->nextCol != NULL){ recursivePrint(tree->nextCol); - }else if (tree->nextRow != NUll){ + } + if (tree->nextRow != NULL){ recursivePrint(tree->nextRow); - }else{ + } + if (tree->nextCol == NULL && tree->nextCol == NULL){ printf("leaf\n"); } diff --git a/CellElemFunc.o b/CellElemFunc.o new file mode 100644 index 0000000..96608af Binary files /dev/null and b/CellElemFunc.o differ diff --git a/CellElement.h b/CellElement.h index d5581bb..67b0a9e 100644 --- a/CellElement.h +++ b/CellElement.h @@ -8,8 +8,8 @@ */ typedef enum Bool{ - true = 1; - false = 0; + true = 1, + false = 0 } bool; @@ -39,6 +39,9 @@ struct cellElement { }; typedef struct cellElement cellElement; +cellElement * CreateCellElem(); +void freeCellElem(cellElement * elem); + int AddNextCol(cellElement* tree); int AddNextRow(cellElement* tree); diff --git a/Exe b/Exe new file mode 100755 index 0000000..c2c0af9 Binary files /dev/null and b/Exe differ diff --git a/Makefile b/Makefile index bf4ff53..6d01a5e 100644 --- a/Makefile +++ b/Makefile @@ -1,35 +1,21 @@ CXX = gcc -TARGET = exe -SOURCEFILE = main -CFLAGS = -Wall -Werror -I. -ansi -pedantic -fpic -g -LIST_LIBRARY = matrix/libMatrix +TARGET = Exe +SOURCEFILE = CellElemFunc +CFLAGS = -Wall -Werror -ansi -pedantic -fpic -I. -g #Generating the executable $(TARGET): $(SOURCEFILE).o - @echo "Generating the executable" - $(CXX) $(CFLAGS) $(SOURCEFILE).o -o $(TARGET) - -$(SOURCEFILE).o: $(LIST_LIBRARY).so - @echo "Generating $(SOURCEFILE).o" - $(CXX) $(CFLAGS) -Lmatrix -lmatrix -c $(SOURCEFILE).c -o $@ -LlibMatrix -llibMatrix.so - -$(LIST_LIBRARY).so:clean - @echo "Generating libMatrix.so" $@ - #gcc matrix.c -I. -Wall -Werror -fpic -shared -o $(LIST_LIBRARY).so - $(CXX) -Wall -Werror -ansi -pedantic -I. matrix.c -o $(LIST_LIBRARY).so -shared -fpic + @echo "Generating the executable" $@ + $(CXX) $(CFLAGS) $(SOURCEFILE).o -o $@ +$(SOURCEFILE).o: + @echo "Generating objectfiles" $@ + $(CXX) $(CFLAGS) -c $(SOURCEFILE).c -o $@ #Cleaning the executable clean: - @echo "Cleaning temporary files and libMatrix.so" + @echo "Cleaning temporary files" rm -rf *.o *- *.so $(TARGET) - rm -rf $(LIST_LIBRARY).so -#Generating library -lib: - @echo "Generating libMatrix.so" - $(CXX) -Wall -Werror -ansi -pedantic -I. matrix.c -o $(LIST_LIBRARY).so -shared -fpic - -release: - @echo "Generating a release version of the program" - make CFLAGS= '-Wall -Werror -I. -ansi -pedantic -fpic' + +