示例#1
0
/**
    @brief Reads tree from file and construct it

    @param file File that will be read
    @param dump_file File that may contain debug info
    @return rtr_val Pointer to constructed tree
*/
Node_t* Node_fread(FILE* file, FILE* dump_file)
{
    assert(file);
    assert(dump_file);

    int temp = WRONG_NUM;
    if (fscanf(file, "(%i)", &temp) > 0 && temp == 0)
    {
        return NULL;
    }

    fscanf(file, "(");

    unsigned char* buffer = (unsigned char*)calloc(MAX_STRLEN, sizeof(*buffer));
    assert(buffer);
    fscanf(file, "\"%[^\"]\"", buffer);

    Node_t* return_node = Node_ctor(buffer, NULL, NULL, dump_file);

    Node_t* left_node = Node_fread(file, dump_file);
    Node_insert(return_node, left_node, LEFT, dump_file);

    Node_t* right_node = Node_fread(file, dump_file);
    Node_insert(return_node, right_node, RIGHT, dump_file);

    fscanf(file, ")");

    VALID_NODE(return_node, "Invalid node in the end of Node_fread", dump_file)
    return return_node;
}
示例#2
0
/*
 * ***************************************************************************
 * Routine:  Bnode_ctor
 *
 * Purpose:  The Block node constructor.
 *
 * Author:   Michael Holst
 * ***************************************************************************
 */
VPUBLIC Bnode* Bnode_ctor(Vmem *vmem, int pnumB, int pnumR[MAXV])
{
    int i;
    Bnode *thee = VNULL;

    VDEBUGIO("Bnode_ctor: CREATING object..");

    thee = Vmem_malloc( VNULL, 1, sizeof(Bnode) );
    if (vmem == VNULL) {
        thee->vmem = Vmem_ctor( "Bnode" );
        thee->iMadeVmem = 1;
    } else {
        thee->vmem = vmem;
        thee->iMadeVmem = 0;
    }

    VDEBUGIO("..done.\n");

    thee->numB   = pnumB;
    for (i=0; i<thee->numB; i++) {
        thee->ND[i] = Node_ctor(vmem, pnumR[i]);
    }

    return thee;
}
示例#3
0
文件: Node.c 项目: hakelimopu/Splorr
Node* Node_new(void * data, Node * next, Node * prev)
{
	Node* ptr = (Node*)SDL_malloc(sizeof(Node));
	Node_ctor(ptr, data, next, prev);
	return ptr;
}