예제 #1
0
int* diffWaysToCompute(char* input, int* returnSize) {
  IntArray operands = int_array();
  IntArray operators = int_array();
  int count = 0;
  /* normalize the string into operands and operators */
  normalize(input, &operands, &operators, &count);
  /* use the normalized data to compute */
  int* result = diffWaysToCompute2(&operands, &operators, count, 0, returnSize);
  int_array_free(&operands);
  int_array_free(&operators);
  return result;
}
예제 #2
0
파일: Utils.cpp 프로젝트: sudarsun/c48
int_array Utils::Sort(int_array &array_Renamed)
{

    int_array index = initialIndex((int)array_Renamed.size());
    int_array newIndex(array_Renamed.size());
    int_array helpIndex;
    int numEqual;

    quickSort(array_Renamed, index, 0, (int)array_Renamed.size() - 1);

    // Make sort stable
    int i = 0;
    while (i < index.size()) {
        numEqual = 1;
        for (int j = i + 1; ((j < index.size()) && (array_Renamed[index[i]] == array_Renamed[index[j]])); j++) {
            numEqual++;
        }
        if (numEqual > 1) {
            helpIndex = int_array(numEqual);
            for (int j = 0; j < numEqual; j++) {
                helpIndex[j] = i + j;
            }
            quickSort(index, helpIndex, 0, numEqual - 1);
            for (int j = 0; j < numEqual; j++) {
                newIndex[i + j] = index[helpIndex[j]];
            }
            i += numEqual;
        }
        else {
            newIndex[i] = index[i];
            i++;
        }
    }
    return newIndex;
}
예제 #3
0
/* remove value at index */
IntArray int_array_rm(IntArray* array_ptr, int length, int index) {
  IntArray array = int_array();
  for (int i = 0; i < length; ++i) {
    if (i < index) {
      int_array_set(&array, i, array_ptr->array[i]);
    }
    if (i == index) {
      continue;
    }
    if (i > index) {
      int_array_set(&array, i - 1, array_ptr->array[i]);
    }
  }
  return array;
}
예제 #4
0
파일: Utils.cpp 프로젝트: sudarsun/c48
int_array Utils::stableSort(double_array &array_Renamed)
{

    int_array index = initialIndex((int)array_Renamed.size());

    if (array_Renamed.size() > 1) {

        int_array newIndex(array_Renamed.size());
        int_array helpIndex;
        int numEqual;

        //array_Renamed = array_Renamed.clone();
        replaceMissingWithMAX_VALUE(array_Renamed);
        quickSort(array_Renamed, index, 0, (int)array_Renamed.size() - 1);

        // Make sort stable

        int i = 0;
        while (i < index.size()) {
            numEqual = 1;
            for (int j = i + 1; ((j < index.size()) && Utils::eq(array_Renamed[index[i]], array_Renamed[index[j]])); j++) {
                numEqual++;
            }
            if (numEqual > 1) {
                helpIndex = int_array(numEqual);
                for (int j = 0; j < numEqual; j++) {
                    helpIndex[j] = i + j;
                }
                quickSort(index, helpIndex, 0, numEqual - 1);
                for (int j = 0; j < numEqual; j++) {
                    newIndex[i + j] = index[helpIndex[j]];
                }
                i += numEqual;
            }
            else {
                newIndex[i] = index[i];
                i++;
            }
        }
        return newIndex;
    }
    else {
        return index;
    }
}
예제 #5
0
int main() 
{
    // instantiate int_array object of class array<int> with size 2
    array< int > int_array(2);

    // set value to a first element
    // call to array class member function to set array elements
    int_array.setArray(0,3);

    // set value to a second element
    // NOTE: any attempt to set float to an int array will be translated to int value
    int_array.setArray(1,3.4);

    // call to array class member function to display array elements
    int_array.getArray();

    // instantiate float_array object of class array<float> with size 3
    array< float > float_array(3);
    // set value to a first element
    // call to array class member function to set array elements
    float_array.setArray(0,3.4);
    // set value to a second element
    float_array.setArray(1,2.8);
    // call to array class member function to display array elements
    float_array.getArray();

    // instantiate float_array object of class 
    // array<char> with size 5
    array< char > char_array(5);

    // set value to a first element
    // call to array class member function to set array elements
    char_array.setArray(0,'H');
    // set value to a other array elements
    char_array.setArray(1,'E');
    char_array.setArray(2,'L');
    char_array.setArray(3,'L');
    char_array.setArray(4,'O');
    char_array.getArray();
    return 0;
 }
예제 #6
0
arma::colvec hobolth_fun(Rcpp::List eigen_dec, double t, int a, int b, int c, int d, int e, int f){
	arma::cx_colvec v=Rcpp::as<arma::cx_colvec>(eigen_dec["values"]);
	arma::cx_mat U=Rcpp::as<arma::cx_mat>(eigen_dec["vectors"]);
	arma::cx_mat U_inv=Rcpp::as<arma::cx_mat>(eigen_dec["invvectors"]);
	int size=v.n_elem;
	
	arma::cx_cube int_array=auxmat2_cpp(v,t);
	arma::cx_colvec temp_sum(1);
	temp_sum(0)=0;
	
	
	
	for(int i=0; i<size;i++){
		for(int j=0; j<size;j++){
			for(int k=0; k<size;k++){
				temp_sum(0)=temp_sum(0)+U(a,i)*U_inv(i,b)*U(c,j)*U_inv(j,d)*U(e,k)*U_inv(k,f)*int_array(i,j,k);     
			}    
		}
	}
	arma::mat out=arma::real(temp_sum);
	return(out);
	
}
예제 #7
0
int* diffWaysToCompute2(IntArray* operands, IntArray* operators, int size,
  int pos, int* returnSize) {
  int count = 0;
  IntArray result = int_array();
  if (size == 0) {
    /* single operator */
    int_array_set(&result, count++, operands->array[0]);
  } else {
    /* recursion, add parenthese at each operator position */
    for (int i = pos; i < size; ++i) {
      int op = operators->array[i];
      int lv = operands->array[i];
      int rv = operands->array[i + 1];
      int value = 0;
      if (op == '+') {
        value = lv + rv;
      } else if (op == '-') {
        value = lv - rv;
      } else {
        value = lv * rv;
      }
      IntArray new_operands = int_array_rm(operands, size + 1, i);
      IntArray new_operators = int_array_rm(operators, size, i);
      int_array_set(&new_operands, i, value);
      int sub_size;
      int* sub = diffWaysToCompute2(&new_operands, &new_operators, size - 1,
        i == 0 ? 0 : i - 1, &sub_size);
      for (int j = 0; j < sub_size; ++j) {
        int_array_set(&result, count++, sub[j]);
      }
      free(sub);
    }
  }
  *returnSize = count;
  return result.array;
}