1
0
mirror of https://gitlab.com/klmp200/LO27.git synced 2024-07-03 10:28:02 +00:00
LO27/LibList/CellElement.c

127 lines
2.0 KiB
C
Raw Normal View History

2016-12-10 01:28:10 +00:00
/***
2016-12-10 01:42:03 +00:00
--- CellElemFunc ---
---Created by : Naej Doree ---
***/
#include <stdio.h>
#include <stdlib.h>
#include <CellElement.h>
2016-12-10 02:55:07 +00:00
cellElement * CreateCellElem(){
cellElement * elem = NULL;
elem = (cellElement*) malloc(sizeof(cellElement));
2016-12-10 01:28:10 +00:00
2016-12-10 02:55:07 +00:00
if (elem == NULL){
return NULL;
}
2016-12-10 01:42:03 +00:00
2016-12-10 02:55:07 +00:00
printf("---Created cellElement---\n");
2016-12-10 01:42:03 +00:00
2016-12-10 02:55:07 +00:00
elem->value = true;
elem->nextCol = NULL;
elem->nextRow = NULL;
2016-12-10 01:28:10 +00:00
return elem;
2016-12-10 02:55:07 +00:00
}
void freeCellElem(cellElement * elem){
free(elem);
elem = NULL;
}
2016-12-10 01:42:03 +00:00
int AddNextCol(cellElement* tree){
2016-12-10 02:55:07 +00:00
cellElement * elem = NULL;
2016-12-10 01:42:03 +00:00
elem = (cellElement*) malloc(sizeof(cellElement));
2016-12-10 01:28:10 +00:00
2016-12-10 01:42:03 +00:00
if (elem == NULL){
return -1;
}
printf("---insertNextCol---\n");
elem->value = true;
elem->nextCol = NULL;
elem->nextRow = NULL;
2016-12-10 02:55:07 +00:00
2016-12-10 01:42:03 +00:00
if (tree->nextCol == NULL){
tree->nextCol = elem;
}else{
return -2;
}
2016-12-10 01:28:10 +00:00
2016-12-10 02:55:07 +00:00
return 1;
2016-12-10 01:42:03 +00:00
}
int AddNextRow(cellElement* tree){
2016-12-10 02:55:07 +00:00
cellElement * elem = NULL;
2016-12-10 01:42:03 +00:00
elem = (cellElement*) malloc(sizeof(cellElement));
2016-12-10 01:28:10 +00:00
2016-12-10 01:42:03 +00:00
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;
}
2016-12-10 02:55:07 +00:00
return 1;
2016-12-10 01:42:03 +00:00
}
void removeNextCol(cellElement* tree){
printf("---removeNextCol---\n");
if (tree->nextCol != NULL){
2016-12-10 02:55:07 +00:00
cellElement * elem = tree->nextCol;
2016-12-10 01:42:03 +00:00
free(elem);
2016-12-10 02:55:07 +00:00
elem = NULL;
tree->nextCol = NULL;
2016-12-10 01:28:10 +00:00
2016-12-10 01:42:03 +00:00
}
}
void removeNextRow(cellElement* tree){
printf("---removeNextRow---\n");
if (tree->nextRow != NULL){
2016-12-10 02:55:07 +00:00
cellElement* elem = tree->nextRow;
2016-12-10 01:42:03 +00:00
free(elem);
elem =NULL;
2016-12-10 02:55:07 +00:00
tree->nextRow = NULL;
2016-12-10 01:28:10 +00:00
2016-12-10 01:42:03 +00:00
}
}
void recursivePrint(cellElement * tree){
if (tree != NULL){
printf("Elem : x: %d y: %d \n",tree->colIndex,tree->rowIndex);
2016-12-10 02:55:07 +00:00
if (tree->nextCol != NULL){
2016-12-10 01:42:03 +00:00
recursivePrint(tree->nextCol);
2016-12-10 02:55:07 +00:00
}
if (tree->nextRow != NULL){
2016-12-10 01:42:03 +00:00
recursivePrint(tree->nextRow);
2016-12-10 02:55:07 +00:00
}
if (tree->nextCol == NULL && tree->nextCol == NULL){
2016-12-10 01:42:03 +00:00
printf("leaf\n");
}
}
2016-12-10 01:28:10 +00:00
}
void FreeCellElement(cellElement* element) {
if (element != NULL){
free(element);
}
}