Exemple #1
0
int main(){
    printf("Before: \n");
    printValues();
    sort();
    printf("After: \n");
    printValues();
    
    return(0);
} // end main
Exemple #2
0
void Log::printValue(const xmlrpc_c::value & value)
{
	std::clog<<" :";
	int vi;
	double vd;
	bool vb;
	time_t vt;
	std::string vs;
	std::map<std::string, xmlrpc_c::value> vstruct;
	std::vector<xmlrpc_c::value> va;
	switch (value.type())
    {
        case xmlrpc_c::value::TYPE_INT:
            fromXmlrpcValue(value, vi);
			std::clog<<" "<<vi<<"\n";
			break;
        case xmlrpc_c::value::TYPE_BOOLEAN:
            fromXmlrpcValue(value, vb);
			std::clog<<" "<<vb<<"\n";
			break;
        case xmlrpc_c::value::TYPE_DOUBLE:
            fromXmlrpcValue(value, vd);
			std::clog<<" "<<vd<<"\n";
			break;
        case xmlrpc_c::value::TYPE_DATETIME:
            fromXmlrpcValue(value, vt);
			std::clog<<" "<<vt<<"\n";
			break;
        case xmlrpc_c::value::TYPE_STRING:
            fromXmlrpcValue(value, vs);
			std::clog<<" "<<vs<<"\n";
			break;
		case xmlrpc_c::value::TYPE_STRUCT:
			fromXmlrpcValue(value, vstruct);
			std::clog<<" struct begin {\n";
			printValues(vstruct);
			std::clog<<"} struct end\n";
            break;
		case xmlrpc_c::value::TYPE_ARRAY:
			fromXmlrpcValue(value, va);
			std::clog<<" array begin {\n";
			printValues(va);
			std::clog<<"} array end\n";
            break;
		/*
        case xmlrpc_c::value::TYPE_BYTESTRING:
            return std::string("TYPE_BYTESTRING");
        case xmlrpc_c::value::TYPE_C_PTR:
            return std::string("TYPE_C_PTR");
        case xmlrpc_c::value::TYPE_NIL:
            return std::string("TYPE_NIL");
        case xmlrpc_c::value::TYPE_DEAD:*/
        default:
            std::clog<<" unknown\n";
    }
}
Exemple #3
0
//Exercise 8
void CFileParser::printAll()
{
	std::cout << "Exercise 8" << std::endl;
	std::cout << "Number of Words: " << _wordsInFile.size() << std::endl;
	std::cout << "Is there an STL word?: " << stlWordExist() << std::endl;
	std::cout << "Last word is: " << _wordsInFile.back() << std::endl;
	std::cout << "Middle word is: " << _wordsInFile.at(((int)_wordsInFile.size() / 2)) << std::endl;
	std::cout << "Number of words with more than 3 characters: " << countWordsWithMoreThan3Chars() << std::endl;
	std::cout << "List of words with less than 4 characters: " << std::endl;
	printValues(getStringsWithLessThanFourChars());
    printValues(_wordsInFile);
}
Exemple #4
0
void insertionSort(int ar_size, int *ar) {    
    int i,j,key=ar[ar_size-1];
    for(i=ar_size-2;i>=0;i--) {
        if(ar[i]>key) {
            ar[i+1] = ar[i];
            printValues(ar,0,ar_size-1);
        }
        else
            break;
    }
    ar[i+1] = key;
    printValues(ar,0,ar_size-1);
}
int main(){

  srand(GetTickCount());
  for(int i=0;i<MAX;i++)
    values[i]=rand()%25;
  printf("Before: \n");
  printValues();
  sort();
  printf("After: \n");
  printValues();

  return(0);
} // end main
int main()
{
  initializeHeap(heap);
  initializeValues();
  buildMaxHeap();
  printValues();
  //printf("max: %d \n",heapExtractMax());
  //heapIncreaseKey(2,18);
  //maxHeapInsert(17);
  printValues();


  return 0;
}
Exemple #7
0
int main(int argc, char* argv[])
{
	//char value = 0x0 | 0x03;
	int values[3] =  {0,1,2};
	//printf("Value: %d\n", (int)value);
	printValues(values, 3);
}
int main ()
{

    int c_memsize = 20;
    int c_valsize = 20;

    // c
    float *c;
    c = (float*)malloc(c_memsize*sizeof(float));
    for (int i = 0; i < c_valsize; ++i)
        c[i] = i;

    // dummy
    Dummy *test = (Dummy*)malloc(sizeof(Dummy));
    test->a = 1;
    test->b = 2;
    test->c = c;
    printValues(test, c_memsize, c_valsize);

    // free
    free(test);
    free(c);

    return 0;
}
Exemple #9
0
//Exercise 7
void printUniqueValues(std::vector<int> vectInt)
{
	std::cout << "Exercise 6/7: " << std::endl;

	std::set<int> setInt(vectInt.begin(), vectInt.end());
	printValues(setInt);
}
Exemple #10
0
//Exercise 5
void printOddValues(std::vector<int> vectInt)
{
	std::cout << "Exercise 5" << std::endl;

	vectInt.erase(std::remove_if(vectInt.begin(), vectInt.end(), std::not1(IsEvenNumber())), vectInt.end());
	printValues(vectInt);
}
Exemple #11
0
void swap(int*a, int*b){
    int c;
        c = *a;
        *a = *b;
        *b = c;
    printValues();
} //swap pointer
Exemple #12
0
void Log::print(const xmlrpc_c::paramList & params)
{
	for(unsigned i=0; i < params.size(); i++) {
		std::clog<<"param["<<i<<"]\n";
		printValues(params.getStruct(i));
	}
}
Exemple #13
0
int main()
{
    doPrint();
    printValue(1);
    std::cout << add(1,1) << std::endl;
    printValues(3, 4);

    return 0;
}
Exemple #14
0
void quickSort(int *ar,int low, int high) {
    int pivot;
    if(low<high) {
        pivot = partition(ar,low,high);
        quickSort(ar,low,pivot-1);
        quickSort(ar,pivot+1,high);
        printValues(ar,low,high);
    }
}
Exemple #15
0
int main(){
    std::array<int, 8> values{1,2, 4, 5, 2, 1, 6, 3};

    Node* firstNode = new Node(values[0]);

    for(int i = 1; i < values.size(); i++)
    {
        insertAtEnd(firstNode, values[i]);
    }

    printValues(firstNode);

    removeDups(firstNode);

    printValues(firstNode);

    delete firstNode;
    
}
Exemple #16
0
void main(void)
{
	int * intArrays[COPIES], i, arraySize, value;
	clrscr();
	printf("This program sorts and searches integer values!\n");
	printf("please give me number of values you wish to deal with: ");
	scanf("%d", &arraySize);

	for(i = 0;i < COPIES; i++)
		intArrays[i] = (int *) malloc(sizeof(int) * arraySize);
	readValues(intArrays, arraySize);

	printf("Enter number to search for? (linear search): ");
	scanf("%d", &value);
	if (linearSearch(intArrays[0], arraySize, value) != -1)
		printf("Found !\n");
	else
		printf("Not Found!\n");
	getch();
	printValues(intArrays, arraySize);
	printf("\nSorting Array 1 using bubble....\n");
	bubble(intArrays[0], arraySize);
	printValues(intArrays, arraySize);

	printf("\nSorting Array 2 using selection....\n");
	selection(intArrays[1], arraySize);
	printValues(intArrays, arraySize);

	printf("\nSorting Array 3 using insertion....\n");
	insertion(intArrays[2], arraySize);
	printValues(intArrays, arraySize);


	printf("Enter number to search for? (binary search): ");
	scanf("%d", &value);
	if (linearSearch(intArrays[0], arraySize, value) != -1)
		printf("Found !\n");
	else
		printf("Not Found!\n");

	getch();
}
Exemple #17
0
int main(void)
{
   int sum = 0;

   int grades[SIZE];
   sum = getValues(grades);   
   printf("\nNumber of scores entered: %d\n", sum);
   printValues(grades, sum);
   
   return 0;
}
void sort()
{

    int i,j;
    for(i=0;i<MAX;i++)//another sort
        for(j=i+1;j<MAX;j++)
            if(values[i]>values[j])
            {
                swap(values[i],values[j]);
                printValues();
            }
}
Exemple #19
0
//Exercise 1
void transformIntToStringVector()
{
	std::cout << "Exercise 1" << std::endl;
	std::vector<int> vectInt = populateVector();

	//std::vector<std::string> stringVector(vectInt.size());
	//std::transform(vectInt.begin(), vectInt.end(), stringVector.begin(), static_cast<std::string(*)(int)>(std::to_string));

	std::vector<std::string> stringVector2;
	std::transform(vectInt.begin(), vectInt.end(), std::back_inserter(stringVector2), static_cast<std::string(*)(int)>(std::to_string));
	printValues(vectInt);
}
Exemple #20
0
void
CSVGAnimateColor::
print(std::ostream &os, bool hier) const
{
  if (hier) {
    os << "<animateColor";

    printValues(os);

    os << "/>" << std::endl;
  }
  else
    os << "animateColor ";
}
Exemple #21
0
int main(){
	char *chunk, *delim = ";";
	//can be replaced with scanf for input.
	char *tmp = "x+=3;y+=5;x*=y;";
	char *str = strdup(tmp);
	chunk = strtok(str, delim);
	while(chunk){
		processString(chunk);
		chunk = strtok(NULL, delim);
	}

	printValues();
	return 0;
}
int main()
{
  initializeHeap(heap);
  initializeValues();
  buildMinHeap();
  printValues();
  //printf("min: %d \n",heapExtractMin());
  //heapDecreaseKey(2,0);
  //minHeapInsert(0);
  //printValues();


  return 0;
}
int main()
{
	enum { NumValues = 10 };

	int fibonacciSequence[NumValues];
	int* fibonacciResults[NumValues];

	setupResultPointers(fibonacciSequence, fibonacciResults, NumValues);

	generateFibonacciSequence(fibonacciSequence, NumValues);

	printValues(fibonacciResults, NumValues);

	return 0;
}
void iteratePrint2(const IterationRange<T1> & iteration1, const IterationRange<T2> & iteration2, const Exp & exp, const Print & print)
{
    std::cout << "        , ";
    printValues(iteration2);
    struct PrintAndIterate
    {
        PrintAndIterate(const IterationRange<T2> & iteration, const Exp & exp, const Print & print) : iteration_(iteration), exp_(exp), print_(print)
        {
        }
        void operator()(T1 val) const
        {
            PrintValue<T1>()(val);
            iterate(iteration_, makePrintExp(std::bind1st(exp_, val), print_));
            std::cout << std::endl;
        }
    private:
        IterationRange<T2> iteration_;
        Exp exp_;
        Print print_;
    };
    iterate(iteration1, PrintAndIterate(iteration2, exp, print));
}
Exemple #25
0
Value* interpereteValue(Token *t){
	Value *v = NULL, *v2 = NULL, *v3 = NULL;
	if(t==NULL) return NULL;
	int nValueBuffOld=nValueBuff;
	int nValueExtraBuffOld = nValueExtraBuff;

	switch (t->type){
		default:
			PERRORTOK("", t);
			v=interpereteValue(t->firstChild);
			break;
		case VALUE:
			v=interpereteValue(t->firstChild);
			break;
		case ASSIGNMENT:
		{
			interpereteValue(t->firstChild->nextSibling);
			v2 = valueBuff + nValueBuff;
			v = interpreteAssignment(getVarName((int)t->firstChild->extra), v2->type, v2->extra);
			break;
		}
		case VARIABLE:
		{
			std::string name(getVarName((int)t->extra));
			v2 = getVal(name);
			v = valueBuff+nValueBuff++;
			switch(v2->type){
				case INTEGER:
					v->type = INTEGER;
					v->extra = valueExtraBuff+nValueExtraBuff;
					*((int*)v->extra) = *((int*)v2->extra);
					nValueExtraBuff+=sizeof(int);
				break;
				case FLOAT:
					v->type = FLOAT;
					v->extra = valueExtraBuff+nValueExtraBuff;
					*((float*)v->extra) = *((float*)v2->extra);
					nValueExtraBuff+=sizeof(float);
				break;
				case STRING:
					v->type = STRING;
					v->extra = valueExtraBuff+nValueExtraBuff;
					strcpy((char*)v->extra, (char*)v2->extra);
					nValueExtraBuff+=strlen((char*)v->extra)+1;
				break;
			}
		}
		break;
		case STRING:
			v = valueBuff+nValueBuff++;
			v->type = STRING;
			v->extra = valueExtraBuff+nValueExtraBuff;
			strcpy((char*)v->extra, (char*)t->extra);
			nValueExtraBuff+=strlen((char*)v->extra)+1;
		break;
		case INTEGER:
			v = valueBuff+nValueBuff++;
			v->type = INTEGER;
			v->extra = valueExtraBuff+nValueExtraBuff;
			*((int*)v->extra) = *((int*)t->extra);
			nValueExtraBuff+=sizeof(int);
		break;
		case FLOAT:
			v = valueBuff+nValueBuff++;
			v->type = FLOAT;
			v->extra = valueExtraBuff+nValueExtraBuff;
			*((float*)v->extra) = *((float*)t->extra);
			nValueExtraBuff+=sizeof(float);
		break;
		case OPERATOR:
			v3 = valueBuff + nValueBuff - 1;
			if (!isOperatorSingle((int)t->extra))
			{
				v2 = valueBuff+nValueBuff-2;
				int type = (int)t->extra;
				if(v2->type < v3->type){
					convert(v2, (int)v3->type);
				}else if(v2->type > v3->type){
					convert(v3, (int)v2->type);
				}
			}
			switch (v3->type){
				case STRING:
					v = interpereteStringOperator(t, v2, v3);
					break;
				case FLOAT:
					v = interpereteFloatOperator(t, v2, v3);
					break;
				case INTEGER:
					v = interpereteIntegerOperator(t, v2, v3);
					break;
			}

			if (!isOperatorSingle((int)t->extra))
				nValueBuff--;
			
		break;
		case FUNC_DEF:
		{
			FuncDefExtra *extra = (FuncDefExtra*)t->extra;
			std::string name(getVarName((int)extra->name->extra));
			v2 = getVal(name);
			v2->type = FUNC_DEF;
			v2->extra = t;
		}
		break;
		case FUNC_CALL:
		{
			FuncCallExtra *extra = (FuncCallExtra*)t->extra;
			std::string name(getVarName((int)extra->name->extra));
			if (name == "print")
			{
				printValues(extra->values);
			}
			else if (name == "scan")
			{
				scanValue();
			}
			else
			{
				Value *val = getVal(name);
				currentStack++;
				Token *funcDefToken = (Token*)val->extra;
				FuncDefExtra *defExtra = (FuncDefExtra*)funcDefToken->extra;

				Token *t_val = extra->values;
				Token *t_def = defExtra->parameters;
				while (t_val)
				{
					interpereteValue(t_val->firstChild);
					v2 = valueBuff + nValueBuff;

					interpreteAssignment(getVarName((int)t_def->extra), v2->type, v2->extra);
					t_val = t_val->nextSibling;
					t_def = t_def->nextSibling;
				}

				interpreteFlow(defExtra->func_body);
				currentStack--;
			}
		}
		break;
	}
	v2 = interpereteValue(t->nextSibling);
	nValueBuff = nValueBuffOld;
	nValueExtraBuff = nValueExtraBuffOld;
	return v2?v2:v;
}
// swap two values at two given memory addresses
void swap(int* a, int* b){
    int temp = *a;
    *a = *b;
    *b = temp;
    printValues();
} // end swap
inline void iteratePrint1(const IterationRange<T> & iteration, const Exp & exp, const Print & print)
{
    printValues(iteration);
    iterate(iteration, PrintExp<Exp, Print>(exp, print));
}
int main()
{
    printValues(6, 7);
    return 0;
}
Exemple #29
0
int main() {
    /************************************************************/
    /* */
    /* ここに課題のプログラムを書く. */
    /* */
    /* 関数 read_matrix() を呼ぶことで,標準入力から連立一次 */
    /* 方程式の次数および各係数を読み込む.その結果, */
    /* 次数が大域変数 n に, */
    /* 係数行列 A と右辺ベクトル b を合わせた拡大行列 [A b] が */
    /* 帯域変数 a[][] に,それぞれ格納される. */
    /* なお,a[][]の内部は */
    /* A → a[1][1] ... a[n][n] , */
    /* b → a[1][n+1] ... a[n][n+1] */
    /* のようになっている. */
    /* */
    /* 関数 print_matrix() は a[][] の内容を標準出力に */
    /* 出力する.アルゴリズムのデバッグに活用すべし. */
    /* */
    /************************************************************/


    /* 以下はサンプルプログラムで,行列を読み込んでそのまま出力する.*/

    /* 標準入力を読み込んで,係数行列を a[][] に,次数を n に格納する */
    if (read_matrix() != 0) {	/* 返り値が 0 以外であればエラー */
        fprintf(stderr, "input error!\n");
        return -1;
    }

    /* 現在の係数行列 a[][] の内容を出力する */
    print_matrix();

    /* ここにガウス消去法などの課題のプログラムを書く */

    // Instead of Gaussian elimination, we'll use gauss-seidel method this

    // These 2 variables are used to test every cases of swapping (like a
    // bubble sort)
    int rowToSwap;
    int rowToSwap2;
    int allCombinations;
    for (allCombinations = 0; allCombinations < n; allCombinations++) {
        for (rowToSwap = 1; rowToSwap < n; rowToSwap++) {
            for (rowToSwap2 = n; rowToSwap2 >= 1; rowToSwap2--) {

                double values[MAXN] = {0};
                double prev_values[MAXN] = {0};
                
                // Checking if the equations are solved for x_1, x_2 ...
                print_matrix();

                // Repeat this loop N times at maximum
                int i, j, k;
                int invalidDivision = 0;
                for (i = 0; i < N; i++) {

                    for (j = 1; j <= n; j++) {

                        if (a[j][j] == 0) {
                            invalidDivision = 1;
                            break;
                        }

                        // Initialize before starting
                        values[j - 1] = 0;

                        for (k = 1; k <= n; k++) {


                            double multi = values[k - 1];
                            if (k == j)
                                multi = 0;

                            // Since j starts from 1
                            // The sign will be flipped when moving to the right side
//printf("values[%d]: %f += %f * %f\n", j - 1, values[j - 1], -(a[j][k] / a[j][j]), multi);
                            values[j - 1] += -(a[j][k] / a[j][j]) * multi;
                        }

                        if (a[j][j] == 0)
                            break;

//printf("values[%d] = %f (%f += %f)\n", j - 1, values[j - 1] + a[j][n + 1] / a[j][j], values[j - 1], a[j][n + 1] / a[j][j]);
                        // Add the integer (= Matrix "b")
                        values[j - 1] += a[j][n + 1] / a[j][j];
                    }

                    if (invalidDivision == 1)
                        break;

                    // After the whole matrix has been processed, check if the result
                    // was accurate enough.
                    double d = findMaxDelta(values, prev_values);
                    printf("d: %f\n", d);

                    // Stop when it becomes accurate enough
                    if (d <= epsilon) {
                        printValues(values);
                        return 0;
                    }
                    // Now, make a backup of the current values (so that we can
                    // calculate the delta in the next loop
                    copyValues(values, prev_values);
                }

                // If the program comes out of this loop, it means that N trials were done
                // but the solutions didn't get accurate enough.
                swapRow(rowToSwap, rowToSwap2);
//printf("swapped %d <=> %d\n", rowToSwap, rowToSwap2);
            }
        }
    }
    // Coming here means there were many attempts of estimating the solution
    // but all the attempts ended up not being accurate enough. It is possible
    // that the epsilon is too small or maybe there's something wrong with the
    // equation.
    printf("The equation set is likely it does not converge.\n");

    /* プログラムの終了 */
    return 0;
}