Пример #1
0
node* nodePost (int pre[], int* preIndex,int low, int high, int size)
{
    // Base case
    if (*preIndex >= size || low > high)
        return NULL;
 
    // The first node in preorder traversal is root. So take the node at
    // preIndex from pre[] and make it root, and increment preIndex
    node* root = nodeInit ( pre[*preIndex] );
    *preIndex = *preIndex + 1;
 
    // If the current subarry has only one element, no need to recur
    if (low == high)
        return root;
 
    // Search for the first element greater than root
    int i;
    for ( i = low; i <= high; ++i )
        if ( pre[ i ] > root->data )
            break;
 
    // Use the index of element found in postorder to divide postorder array in
    // two parts. Left subtree and right subtree
    root->left = nodePost ( pre, preIndex, *preIndex, i - 1, size );
    root->right = nodePost ( pre, preIndex, i, high, size );
 
    return root;
}
Пример #2
0
WdysCtrl::WdysCtrl(ros::NodeHandle nh):
    nh_(nh),
    is_moving(0),
    is_backing(0),
    open_count(0)
{
    nodeInit();

    std_msgs::Int32 start_msg;
    start_msg.data = 1;
    for (int i = 0; i < 5; i++)
        door_signal_publisher_.publish(start_msg);

    printf("WdysCtrl Ready!\n");
}
Пример #3
0
tnode* createTree(char exp[])
{
	tnode *op,*l,*r;
	int i=0,j=1,k;
	while(i<strlen(exp))
	{
		if(isalpha(exp[i]) || exp[i] == '#')
		{
			push(nodeInit(exp[i++],j++));
			continue ;
		}
		op = nodeInit(exp[i++],0);
		if(op->key == '*')
		{
			l = pop();
			op->left = l;
			strcpy(op->first,l->first);
			strcpy(op->last,l->last);
			for(k=0;k<strlen(op->first);k++)
			{
				strcat(follow[op->first[k] - 48] ,op->last);
				strcpy(follow[op->first[k] - 48],rmv(follow[op->first[k] - 48]));
			}
		}
		else
		{
			r = pop();
			l = pop();
			op->left = l;
			op->right = r;
			if( op->key == '/')
			{
				strcpy(op->first,l->first);
				strcat(op->first,r->first);
				strcpy(op->last,l->last);
				strcat(op->last,r->last);
				if(l->nul == 1 || r->nul == 1)
					op->nul = 1;
				else
					op->nul = 0;
			}
			else
			{
				strcpy(op->first,l->first);
				if(l->nul == 1)
					strcat(op->first,r->first);
				strcpy(op->last,r->last);
				if(r->nul == 1)
					strcat(op->last,l->last);
				if(l->nul == 1 && r->nul == 1)
					op->nul = 1;
				else
					op->nul = 0;
				for(k=0;k<strlen(l->last);k++)
				{
					strcat(follow[l->last[k] - 48] ,r->first);
					strcpy(follow[l->last[k] - 48],rmv(follow[l->last[k] - 48]));
				}
			}
		}
		push(op);
	}
	return pop();
}