1
0
mirror of https://gitlab.com/klmp200/LO27.git synced 2024-06-02 02:39:39 +00:00
LO27/CellElemFunc.c
2016-12-10 18:54:03 +01:00

138 lines
2.2 KiB
C
Executable File

/***
--- CellElemFunc ---
---Created by : Naej Doree ---
***/
#include <stdio.h>
#include <stdlib.h>
#include <CellElement.h>
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;
}
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");
}
}
}