From 918e3e9851b8e3b2afd8b17d63e4a307ec0993c3 Mon Sep 17 00:00:00 2001 From: klmp200 Date: Sat, 10 Dec 2016 21:11:46 +0100 Subject: [PATCH] =?UTF-8?q?=C3=87a=20me=20casse=20les=20couilles?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LibList/CellElement.c | 113 +++++++++++++++++++++++++++++++++++++++++- LibList/CellElement.h | 14 +++++- main.c | 22 ++++++-- 3 files changed, 142 insertions(+), 7 deletions(-) diff --git a/LibList/CellElement.c b/LibList/CellElement.c index 7e90729..32824cc 100644 --- a/LibList/CellElement.c +++ b/LibList/CellElement.c @@ -2,13 +2,124 @@ * @Author: klmp200 * @Date: 2016-12-10 01:32:50 * @Last Modified by: klmp200 -* @Last Modified time: 2016-12-10 04:29:48 +* @Last Modified time: 2016-12-10 21:08:25 */ #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..7a603b5 100644 --- a/LibList/CellElement.h +++ b/LibList/CellElement.h @@ -27,7 +27,7 @@ typedef enum Bool{ * */ struct cellElement { - + int colIndex; int rowIndex; @@ -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/main.c b/main.c index 32d1521..1dd9e58 100644 --- a/main.c +++ b/main.c @@ -3,14 +3,28 @@ * Created By : klmp200 * Creation Date : [2016-12-10 01:06] * Last Modified : [2016-12-10 01:07] -* Description : +* Description : **********************************************************************************/ #include #include -int main(int argc, char *argv[]) -{ - printf("Hello World\n"); +#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; + }