コード例 #1
0
int commandMathOperator(const char* item){
	if( P_Vacia(*stack) ){
		puts("La pila esta vacia");
		return OK;
	}
	double* firstIn;
	double* secondIn;
	double* result = malloc(sizeof(double));
	P_Sacar(stack, secondIn);
	P_Sacar(stack, firstIn);

	if( strcmp(item, "+") == 0 ){
		*result = *firstIn + *secondIn;
	} else if( strcmp(item, "-") == 0 ){
		*result = *firstIn + *secondIn;
	} else if( strcmp(item, "*") == 0 ){
		*result = *firstIn * *secondIn;
	} else if( strcmp(item, "/") == 0 ){
		*result = *firstIn / *secondIn;
	} else if( strcmp(item, "%") == 0 ){
		//*result = *firstIn % *secondIn; //TODO: ver esto!
		*result = 10000;	// dummy
	}
	P_Poner(stack, result);
	return OK;
}
コード例 #2
0
int commandR(){
	//Invierte el orden del primer y segundo elemento de la pila.
	if( P_Vacia(*stack) ){
		puts("La pila esta vacia");
	}else{
		double* first;
		double* second;
		P_Sacar(stack, first);
		P_Sacar(stack, second);
		P_Poner(stack, first);
		P_Poner(stack, second);
	}
	return OK;
}
コード例 #3
0
ファイル: TDA_Expresion.c プロジェクト: manuporto/fp-facultad
/**
@function
@name
@description
@return
@param
@param
@param
@author
@see -
*/
int ParsearAux (TExpresion *expr, TPila *sufijo, int mov)
{
    int error;
    int tipoOperador;
    TLiteral auxLiteral;

    if (P_Vacia(*sufijo)) return 0;

    P_Sacar(sufijo,&auxLiteral);
    tipoOperador = Literal_EsOperador(&auxLiteral); /* 2: Binario. 1: Unario. 0: no operador. */
/*    printf ("%s es operador: %i\n",auxLiteral.valor,tipoOperador);
    printf ("Elem a ingresar: %s\n",auxLiteral.valor);
*/    AB_Insertar((&expr->expresion),mov,&auxLiteral,&error);

    if (tipoOperador==2)
    {
        ParsearAux (expr, sufijo, DER);
        ParsearAux (expr, sufijo, IZQ);
    }

    if (tipoOperador==1)
    {
        ParsearAux (expr, sufijo, DER);
    }

    AB_MoverCte(&(expr->expresion),PAD,&error);

    return 0;
}
コード例 #4
0
int commandN(){
	// Toma el valor del tope de la pila y lo imprime, sin agregar un caracter de fin de linea.
	if( P_Vacia(*stack) ){
		puts("La pila esta vacia");
	}else{
		double* element;
		P_Sacar(stack, element );
		P_Poner(stack, element);
		printf("%f", *element);
	}
	return OK;
}
コード例 #5
0
int commandP(){
	// Imprime el valor delfree(element); tope de la pila, sin alterar la pila. Agrega un caracter de fin de line
	if( P_Vacia(*stack) ){
		puts("La pila esta vacia");
	}else{
		double* element;
		P_Sacar(stack, element );
		P_Poner(stack, element);
		printf("%f\n", *element);
	}
	return OK;
}
コード例 #6
0
int commandV(){
	// Calcula el valor de la raiz cuadrada del elemento en el tope de la pila.
	if( P_Vacia(*stack) ){
		puts("La pila esta vacia");
		return OK;
	}
	double* element;
	double* result = malloc(sizeof(double));
	P_Sacar(stack, element);
	*result = sqrt(*element);
	P_Poner(stack, result);
	return OK;
}
コード例 #7
0
int commandF(){
	// Vacia el contenido de la pile imprimiendo resultados
	if( P_Vacia(*stack) ){
		puts("La pila esta vacia");
	}else{
		double* element;
		while( !P_Vacia(*stack) ){
			P_Sacar(stack, element);
			printf("%f", *element);
		}
	}
	return OK;
}
コード例 #8
0
/**
@function
@name TIN_GetEstados
@description Obtiene todos los estados que tuvo una incidencia y los devuelve en una pila
@return int
@param tin:TIN*
@param estados:TPila*
@author Batman
@see -
*/
int TIN_GetEstados(TIN* tin, TPila* estados)
{
    TPila pilaAux;
    inci_status_t statAux;

    P_Crear (&pilaAux,sizeof(inci_status_t));

    while(!P_Vacia(tin->inci_stat_hist))
    {
         P_Sacar(&(tin->inci_stat_hist),&statAux);
         P_Agregar(&pilaAux,&statAux);
    }

    while(!P_Vacia(pilaAux))
    {
        P_Sacar (&pilaAux,&statAux);
        P_Agregar (&(tin->inci_stat_hist),&statAux);
        P_Agregar (estados,&statAux);
    }

    return RES_OK;
}
コード例 #9
0
int commandD(){
	// Duplica el valor en la cima de la pila.
	if( P_Vacia(*stack) ){
		puts("La pila esta vacia");
	}else{
		double* element;
		double* duplicate = malloc(sizeof(double));
		P_Sacar(stack, element );
		P_Poner(stack, element);
		*duplicate = *element;
		P_Poner(stack, duplicate);
	}
	return OK;
}
コード例 #10
0
/**
@function
@name TIN_Liberar
@description Elimina y libera todas las estructuras que forman parte del TIN.
@return int
@param tin:TIN*
@author Batman
@see -
*/
int TIN_Liberar( TIN* tin){

    int sacar = 10;

    inci_status_t statusaux;
    inci_comment_t commaux;

    free (tin->inci_date_created);
    tin->inci_date_created = NULL;
    free (tin->inci_summary);
    tin->inci_summary = NULL;

    free (tin->inci_description);
    tin->inci_description = NULL;

    free (tin->inci_date_solved);
    tin->inci_date_solved = NULL;

    while (!P_Vacia(tin->inci_stat_hist))
    {
        sacar = P_Sacar(&(tin->inci_stat_hist),&statusaux);
        free (statusaux.stat_date);
        statusaux.stat_date= NULL;
    }

    while (!C_Vacia(tin->inci_comm))
    {
        C_Sacar(&(tin->inci_comm),&commaux);
        free (commaux.comm_date);
        commaux.comm_date= NULL;
        free (commaux.comm_desc);
        commaux.comm_desc= NULL;
    }
    C_Vaciar(&(tin->inci_comm));
    return RES_OK;
}