/*** --- CellElemFunc --- ---Created by : Naej Doree --- ***/ #include #include #include cellElement * CreateCellElem(){ cellElement * elem = NULL; elem = (cellElement*) malloc(sizeof(cellElement)); if (elem == NULL){ return NULL; } elem->nextCol = NULL; elem->nextRow = NULL; return elem; } bool is_leaf(cellElement* tree){ if (tree->nextCol == NULL && tree->nextRow == NULL){ return true; } else { return false; } } int SetPositionIndex(cellElement* elem,int Col,int Row){ if (elem != NULL){ elem->colIndex = Col; elem->rowIndex = Row; } else { return -1; } return 1; } int SetNextCol(cellElement* tree,cellElement* elem){ if (tree->nextCol == NULL){ tree->nextCol = elem; }else{ return -2; } 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; } return(SetNextCol(tree,elem)); } int AddNextRow(cellElement* tree){ cellElement * elem = NULL; elem = CreateCellElem(); if (elem == NULL){ return -1; } return(SetNextRow(tree,elem)); } void removeNextCol(cellElement* tree){ if (tree->nextCol != NULL){ free(tree->nextCol); tree->nextCol = NULL; } } void removeNextRow(cellElement* tree){ if (tree->nextRow != NULL){ free(tree->nextRow); tree->nextRow = NULL; } } void recursivePrint(cellElement * tree){ if (tree != NULL){ printf("Elem : x: %d y: %d \n",tree->colIndex,tree->rowIndex); if (is_leaf(tree)){ printf("leaf\n"); } else { if (tree->nextCol != NULL){ recursivePrint(tree->nextCol); } if (tree->nextRow != NULL){ recursivePrint(tree->nextRow); } } } } void FreeCellElement(cellElement* element) { if (element != NULL){ free(element); }else{ printf("Cant free NULL"); } element = NULL; } bool OR(bool a, bool b){ if (a || b){ return true; } else { return false; } } bool AND(bool a, bool b){ if (a && b){ return true; } else { return false; } } bool XOR(bool a, bool b){ if (!(a && b) && (a||b)){ return true; } else { return false; } } bool ErrorToFalse(bool x){ if (x == ERROR){ return false; } return x; }