Beispiel #1
0
int infix2postfix(char *p) {
	// inplace replacing, newp will point to the end of the new expression.
	char *newp = p;
	int opr;
	stack op_stk = SNew(TYPE_INT);
	for(; *p != '\0'; ++p) {
		switch(OPNUM(*p)) {
			case IS_OPERATOR: // beware it's a GNU extension.
				if(*p == ')') {
					while(SPop(op_stk, &opr), opr != '(')
						*(newp++) = opr;
					break;
				}
				else if(SEmpty(op_stk));
				else if(isp[OPNUM(STop(op_stk))] >= icp[OPNUM(*p)]) {
					SPop(op_stk, &opr);
					*(newp++) = opr;
				}
				SPush(op_stk, *p);
				break;
			default:
				*(newp++) = *p;
		}
	}
	while(!SEmpty(op_stk)) {
		SPop(op_stk, &opr);
		*(newp++) = opr;
	}
	*newp = '\0';
	return 0;
}
Beispiel #2
0
static Result XXX_PushOpr(Stack *sopr, Stack *sval, int opr) {
    Result res = R_SUCCE;
    long double tmp;
    long double *ans;
    while (!SEmpty(sopr) && XXX_ShouldPop(*STopInt(sopr), opr)) {
        switch (SPopInt(sopr)) {
        case OPR_TRM:
            return R_ITRNL;
        case BIN_ADD:
            XXXPO_EVOB(*ans += tmp);
        case BIN_SUB:
            XXXPO_EVOB(*ans -= tmp);
        case BIN_MUL:
            XXXPO_EVOB(*ans *= tmp);
        case BIN_DIV:
            XXXPO_EVOB(*ans /= tmp);
        case BIN_MOD:
            XXXPO_EVOB(*ans = fmodl(*ans, tmp));
        case BIN_PWR:
            XXXPO_EVOB(*ans = powl(*ans, tmp));
        case UNA_PLS:
            XXXPO_EVOU();
        case UNA_MNS:
            XXXPO_EVOU(*ans = -*ans);
        default:
            return R_ITRNL;
        }
        if ((res = RMathType(*ans)))
            return ERR(res);
    }
    if (SPushInt(sopr, opr))
        return R_ITRNL;
    return R_SUCCE;
}
Beispiel #3
0
//------------------------------------------------------------
//clear or destroy
int 
clear( bvs_ptr tree )
{
  ptr_IStackA stack = newStack( sizeof(node_ptr) ); //zasobnik ukazatelov
  if ( stack == NULL )
    return TREE_ERROR;
    
    
  node_ptr curr_node = tree->root; // korenovy ukazatel
  node_ptr ptr;                    //pomocny ukazatel uzla
  
  while ( (curr_node != NULL) || (SEmpty(stack) != 1) )
  {
    if (curr_node == NULL){
      curr_node = *((node_ptr * )Stop(stack));
      Spop(stack);
      }
    else
    {
      if (curr_node->right != NULL)     //ulozenie praveeho podstromu
        Spush(stack, &(curr_node->right));
        
      ptr = curr_node;
      curr_node=curr_node->left;
      destroyNode(ptr);
      free(ptr);      
    }      
  }
  destroyStack(stack);
  free(stack);
  return TREE_OK;
}
Beispiel #4
0
int match_parentheses(char *p) {
	int op;
	stack pr_stk = SNew(TYPE_INT);
	for(; *p != '\0'; ++p) {
		if(*p == '(' || *p == '[' || *p == '{')
			SPush(pr_stk, *p);
		else if(*p == ')' || *p == ']' || *p == '}') {
			if(SEmpty(pr_stk)) return -1;
			SPop(pr_stk, &op);
			if(*p == ')' && op != '(') return -1;
			if(*p ==']' && op != '[') return -1;
			if(*p =='}' && op != '{') return -1;
		}
	}
	if(!SEmpty(pr_stk)) return -1;
	return 0;
}
Beispiel #5
0
void
Spop ( ptr_IStackA stck )
{

  if ( SEmpty (stck) != 1 )
  {
 
  (stck->top_index)--;
  
  if ( stck->top_index*stck->elem_size < (stck->elem_size -32 ))
  {
    //realokacia ?
  }
  }
  
}