Ejemplo n.º 1
0
int node_get_count(p_node root, int *cnt)
{
	int c_cnt = node_get_child_count(root);
	if (c_cnt == 0)
	{
		return 0;
	}
	*cnt += c_cnt;
	node_get_count(root->child, cnt);
	node_get_count(root->next, cnt);
	return 0;
}
Ejemplo n.º 2
0
/**
 * Counts the no. of node in a linked list
 */
int node_get_count(Node *head) {
	if (head) {
		return 1 + node_get_count(head->next);
	} else {
		return 0;
	}
}
Ejemplo n.º 3
0
int node_init_status(p_node root, p_node *stat, int *cnt)
{
	int base = 0;
	int cur = 1;
	int tmp = 0;
	int max = 0;
	node_get_count(root, &max);
	*cnt = max;
	int i;
	p_node p;
	stat[0]= root;

	while(1)
	{
		tmp= cur;
		if (tmp> max)
			break;
		for (i= base; i< tmp; i++)
		{
			p = stat[i]->child;
			while (p)
			{
				stat[cur] = p;
				cur++;
				p=p->next;
			}
		}
		base= tmp;
	}

}
Ejemplo n.º 4
0
int main(int argc, char *argv[])
{
	p_node root = node_init();
	int i = 0;

	printf("Please input pattern number:");
	int num = 0;
	scanf("%d",&num);
	char tmp_str[MAX_SIZE];
	printf("Please input patterns:\n");
	while(num)
    {
        scanf("%s", tmp_str);
        insert_str(root, tmp_str);
        num --;
    }


	node_get_count(root, &i);
	node_init_status(root, status, &status_count);
	ac_create();
	printf("base:");
	for (i = 0; i < status_count; i++)
	{
        printf("%d ", ac_base[i]);
	}
	printf("\nnext:");
	for (i = 0; i < status_count; i++)
	{
        printf("%d ", ac_next[i]);
	}
	printf("\ncheck:");
	for (i = 0; i < status_count; i++)
	{
        printf("%d ", ac_check[i]);
	}
	printf("\nPlease input txt:");
	scanf("%s", tmp_str);
	run(tmp_str);
	return 0;
}