//cell.h
typedef struct cellCDT *cell;
cell new_cell(void); /* create new cell*/
void create_child( cell x, int y); /*creates a child in given cells children area with value*/
void free_cell( cell x ); /* frees cell */
float get_val(cell x); /*return strng held in cell*/
void c_val(cell x, float y); /* change value of cell*/
cell lreturn(cell x);
cell rreturn(cell x);
---------------------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cell.h"
struct cellCDT{
struct cellCDT* left; //struct of each cell uniform across all
struct cellCDT* right; //due to laziness
float value;
}
/*//////////////////////////////////////////////////////////
// creates and initializes new cell with no input
//
//////////////////////////////////////////////////////////*/
void new_cell()
{
cell new = (cell)malloc( sizeof(*new) );
new->left=NULL;
new->right=NULL;
new->value=0;
return new;
}
/*********************************************************
** create child under a cell and add pointer to that cell's newly expanded
**array
******************************************************************************/
void create_child( cell x, int y)
{
cell child_cell = new_cell();
if(y==0)
{
x->left = child_cell;
//innate bias to do nothing
}
else x->right = child_cell;
}
/***************frees all parts of cell and then frees self*******************/
void free_cell( cell x )
{
if(x->left != NULL) free_cell(x->left);
if(x->right != NULL) free_cell(x->right);
free(x);
}
/***************return strng held in cell*************************************/
float get_val(cell x)
{
return x->value;
}
/**************change value of cell******************************************/
void c_val(cell x, float y)
{
x->value = x->value + y;
}
cell lreturn(cell x)
{
return x->left;
}
cell rreturn(cell x)
{
return x->right;
}
|