2016-12-10 01:28:10 +00:00
|
|
|
/***
|
|
|
|
--- CellElemFunc ---
|
|
|
|
---Created by : Naej Doree ---
|
|
|
|
***/
|
2016-12-10 01:28:10 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2016-12-10 04:04:13 +00:00
|
|
|
#include <CellElement.h>
|
2016-12-10 01:28:10 +00:00
|
|
|
|
2016-12-10 20:11:46 +00:00
|
|
|
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;
|
|
|
|
|
2016-12-10 01:28:10 +00:00
|
|
|
return elem;
|
2016-12-10 20:11:46 +00:00
|
|
|
}
|
|
|
|
|
2016-12-11 01:32:51 +00:00
|
|
|
bool is_leaf(cellElement* tree){
|
|
|
|
if (tree->nextCol == NULL && tree->nextRow == NULL){
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-11 02:09:57 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-12-10 20:11:46 +00:00
|
|
|
int AddNextCol(cellElement* tree){
|
|
|
|
|
|
|
|
cellElement * elem = NULL;
|
2016-12-11 02:25:21 +00:00
|
|
|
|
|
|
|
printf("---insertNextCol---\n");
|
|
|
|
|
2016-12-11 02:09:57 +00:00
|
|
|
elem = CreateCellElem();
|
2016-12-10 01:28:10 +00:00
|
|
|
|
2016-12-10 20:11:46 +00:00
|
|
|
if (elem == NULL){
|
|
|
|
return -1;
|
|
|
|
}
|
2016-12-11 02:09:57 +00:00
|
|
|
return(SetNextCol(tree,elem));
|
2016-12-11 02:25:21 +00:00
|
|
|
|
2016-12-10 20:11:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int AddNextRow(cellElement* tree){
|
|
|
|
|
|
|
|
cellElement * elem = NULL;
|
2016-12-11 02:25:21 +00:00
|
|
|
|
|
|
|
printf("---insertNextRow---\n");
|
|
|
|
|
2016-12-11 02:09:57 +00:00
|
|
|
elem = CreateCellElem();
|
2016-12-10 01:28:10 +00:00
|
|
|
|
2016-12-10 20:11:46 +00:00
|
|
|
if (elem == NULL){
|
|
|
|
return -1;
|
|
|
|
}
|
2016-12-11 02:09:57 +00:00
|
|
|
return(SetNextRow(tree,elem));
|
2016-12-11 02:25:21 +00:00
|
|
|
|
2016-12-10 20:11:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void removeNextCol(cellElement* tree){
|
|
|
|
printf("---removeNextCol---\n");
|
|
|
|
|
|
|
|
if (tree->nextCol != NULL){
|
2016-12-11 01:32:51 +00:00
|
|
|
free(tree->nextCol);
|
2016-12-10 20:11:46 +00:00
|
|
|
tree->nextCol = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void removeNextRow(cellElement* tree){
|
|
|
|
printf("---removeNextRow---\n");
|
|
|
|
|
|
|
|
if (tree->nextRow != NULL){
|
2016-12-11 01:32:51 +00:00
|
|
|
free(tree->nextRow);
|
2016-12-10 20:11:46 +00:00
|
|
|
tree->nextRow = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
void recursivePrint(cellElement * tree){
|
|
|
|
if (tree != NULL){
|
|
|
|
printf("Elem : x: %d y: %d \n",tree->colIndex,tree->rowIndex);
|
2016-12-11 01:32:51 +00:00
|
|
|
if (is_leaf(tree)){
|
2016-12-10 20:11:46 +00:00
|
|
|
printf("leaf\n");
|
2016-12-11 01:32:51 +00:00
|
|
|
} else {
|
|
|
|
if (tree->nextCol != NULL){
|
|
|
|
recursivePrint(tree->nextCol);
|
|
|
|
}
|
|
|
|
if (tree->nextRow != NULL){
|
|
|
|
recursivePrint(tree->nextRow);
|
|
|
|
}
|
2016-12-10 20:11:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-10 04:04:13 +00:00
|
|
|
void FreeCellElement(cellElement* element) {
|
2016-12-10 01:28:10 +00:00
|
|
|
if (element != NULL){
|
|
|
|
free(element);
|
|
|
|
}
|
2016-12-10 23:33:02 +00:00
|
|
|
element = NULL;
|
2016-12-10 04:04:13 +00:00
|
|
|
}
|