1
0
mirror of https://gitlab.com/klmp200/LO27.git synced 2024-11-16 18:13:18 +00:00
LO27/LibAutomaton/CellElement.c
2016-12-11 04:01:27 +01:00

135 lines
2.1 KiB
C

/***
--- CellElemFunc ---
---Created by : Naej Doree ---
***/
#include <stdio.h>
#include <stdlib.h>
#include <CellElement.h>
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;
}
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;
printf("---insertNextCol---\n");
elem = CreateCellElem();
if (elem == NULL){
return -1;
}
return(SetNextCol(tree,elem));
}
int AddNextRow(cellElement* tree){
cellElement * elem = NULL;
printf("---insertNextRow---\n");
elem = CreateCellElem();
if (elem == NULL){
return -1;
}
return(SetNextRow(tree,elem));
}
void removeNextCol(cellElement* tree){
printf("---removeNextCol---\n");
if (tree->nextCol != NULL){
free(tree->nextCol);
tree->nextCol = NULL;
}
}
void removeNextRow(cellElement* tree){
printf("---removeNextRow---\n");
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);
}
element = NULL;
}