コード例 #1
0
int main()
{
	Tree *head = new Tree;
	head->value = -32999;
	head->left = NULL;
	head->right = NULL;
	head->prev = NULL;

	char c = 0;

	while (c != '0')
	{
		printf("\n	0 Exit\n	1 Add value to tree\n	2 Delete value from tree\n	3 Exist?\n	4 Print\n	");
		scanf("%c", &c);
		if (c == '\n')
			scanf("%c", &c);
		if (c == '1')
			addValue(head);
		if (c == '2')
			delValue(head);
		if (c == '3')
			existence(head);
		if (c == '4')
			printEl(head->left);
	}
	
	
	delTree(head->left);
	delete head;	
	return 0;
}
コード例 #2
0
ファイル: main.cpp プロジェクト: AidaKadyrova/my-homeworks
int main()
{
	List* procedure = createList();
	FILE *file = fopen("input.txt","r");
	read(file, procedure);
	fclose(file);
    printEl(mergeSort(procedure));
	printf("\n");
	return 0;
}
コード例 #3
0
scp_result is_procedure_operator_breakpoint(scp_operand *scp_operator)
{
    if (SCP_RESULT_TRUE != find_breakpoints_set())
    {
        return SCP_RESULT_FALSE;
    }

    scp_operand arc;
    MAKE_DEFAULT_ARC_ASSIGN(arc);
    scp_iterator3 *it = scp_iterator3_new(s_default_ctx, &current_breakpoints_set, &arc, &scp_operator);
    if (SCP_RESULT_TRUE != scp_iterator3_next(s_default_ctx, it, &current_breakpoints_set, &arc, &scp_operator))
    {
        printf("Procedure operator ");
        printEl(s_default_ctx, scp_operator);
        printf(" isn't breakpoint\n");
        return SCP_RESULT_FALSE;
    }

    scp_iterator3_free(it);
    printf("Procedure operator ");
    printEl(s_default_ctx, scp_operator);
    printf(" is breakpoint\n");
    return SCP_RESULT_TRUE;
}
コード例 #4
0
scp_result genElStr5(scp_operand *param1, scp_operand *param2, scp_operand *param3, scp_operand *param4, scp_operand *param5)
{
    sc_uint32 fixed1 = 0;
    sc_uint32 fixed3 = 0;
    sc_uint32 fixed5 = 0;
    sc_uint32 fixed = 0;
    if (param2->param_type == SCP_FIXED)
    {
        return print_error("genElStr5", "Parameter 2 must have ASSIGN modifier");
    }
    if (param4->param_type == SCP_FIXED)
    {
        return print_error("genElStr5", "Parameter 4 must have ASSIGN modifier");
    }
    if (param1->param_type == SCP_FIXED)
    {
        if (SC_FALSE == sc_memory_is_element(param1->addr))
        {
            return print_error("genElStr5", "Parameter 1 has modifier FIXED, but has not value");
        }
        fixed1 = 0x1;
    }
    if (param3->param_type == SCP_FIXED)
    {
        if (SC_FALSE == sc_memory_is_element(param3->addr))
        {
            printEl(param1);
            return print_error("genElStr5", "Parameter 3 has modifier FIXED, but has not value");
        }
        fixed3 = 0x100;
    }
    if (param5->param_type == SCP_FIXED)
    {
        if (SC_FALSE == sc_memory_is_element(param5->addr))
        {
            return print_error("genElStr5", "Parameter 5 has modifier FIXED, but has not value");
        }
        fixed5 = 0x10000;
    }
    fixed = (fixed1 | fixed3 | fixed5);
    switch (fixed)
    {
        case 0x10101:
            return genElStr5_f_a_f_a_f(param1, param2, param3, param4, param5);
        case 0x00101:
            return genElStr5_f_a_f_a_a(param1, param2, param3, param4, param5);
        case 0x10001:
            return genElStr5_f_a_a_a_f(param1, param2, param3, param4, param5);
        case 0x10100:
            return genElStr5_a_a_f_a_f(param1, param2, param3, param4, param5);
        case 0x10000:
            return genElStr5_a_a_a_a_f(param1, param2, param3, param4, param5);
        case 0x00100:
            return genElStr5_a_a_f_a_a(param1, param2, param3, param4, param5);
        case 0x00001:
            return genElStr5_f_a_a_a_a(param1, param2, param3, param4, param5);
        case 0x00000:
            return genElStr5_a_a_a_a_a(param1, param2, param3, param4, param5);
        default:
            return print_error("genElStr5", "Unsupported parameter type combination");
    }
    return SCP_RESULT_ERROR;
}
コード例 #5
0
void print_element(scp_operand element) {
//    scp_param_type param_type = element.param_type;
//	element.param_type = SCP_FIXED;
	printEl(s_default_ctx, &element);
//	element.param_type = param_type;
}
コード例 #6
0
int main(void)
{
    int length = 0, height = 0, i, k, lowVal = -1000, highVal = -1000;
    char entred[100] = "";

    do{
        drawField(COLS/4, ROWS/4, COLS/2, ROWS/2);
        k = setText(COLS/4 + 2, 3*ROWS/8, "Enter matrix length [1..9]\n& height [1..9]\nparting values with coma:", FIELD_COLOR);
        getText(COLS/4 + 2, 3*ROWS/8 + k + 1, entred, FIELD_BACKGROUND, FORE_BLACK);
        getPartiedInts(entred, &length, &height);
        if((length > 9 || length < 1) || (height > 9 || height< 1)){
            setTextLine(COLS/4 + 2, 3*ROWS/8 + k + 4, "Invalid input!", FIELD_BACKGROUND | FOREGROUND_RED);
            Sleep(1500);
        }
    }while((length > 9 || length < 1) || (height > 9 || height< 1));

    do{
        drawField(COLS/4, ROWS/4, COLS/2, ROWS/2);
        k = setText(COLS/4 + 2, 3*ROWS/8, "Enter matrix random values diapason\nparting left & right bounds with coma:", FIELD_COLOR);
        getText(COLS/4 + 2, 3*ROWS/8 + k + 1, entred, FIELD_BACKGROUND, FORE_BLACK);
        getPartiedInts(entred, &lowVal, &highVal);
        if((lowVal > highVal) || (highVal > 999) || (lowVal < -999)){
            setTextLine(COLS/4 + 2, 3*ROWS/8 + k + 4, "Invalid input!", FIELD_BACKGROUND | FOREGROUND_RED);
            Sleep(1500);
        }
    }while((lowVal > highVal) || (highVal > 999) || (lowVal < -999));


    int matr[height][length], mcpy[length][height], isTurned = 0, toSwitch = 0, firstToSwap, secondToSwap;
    int cX, cY, val, row;
    fillRand(length, height, matr, lowVal, highVal);

    int y = 2 + height*2;

    short color = FIELD_COLOR, toClean = 0, isSwaped = 0, help = 0, toPickOutCols = 0, toYellow = 0, toPickOutRow = 0;
    char * g, cpy[100];
    COORD swaped[2];
    clearScr();
    drawField(0, 0, COLS - 1, y);

    while(1){
        y = isTurned ? (2 + length*2) : (2 + height*2);
        if(toClean){
            toClean = 0;
            clean(y);
        }
        printMatr(length, height, matr, isTurned, toSwitch, color);
        color = FIELD_COLOR;

        if(isSwaped){
            pickOut(length, height, matr, isTurned, swaped[0], BACKGROUND_GREEN);
            pickOut(length, height, matr, isTurned, swaped[1], BACKGROUND_RED);
            isSwaped = 0;
        } else if(toYellow){
            printEl(length, height, matr, isTurned, cX - 1, cY - 1, FORE_YELLOW | FIELD_BACKGROUND | FOREGROUND_INTENSITY);
            toYellow = 0;
        } else if(toPickOutRow){
            pickOutRow(length, height, matr, isTurned, row - 1, BACKGROUND_GREEN);
            toPickOutRow = 0;
        } else if(toPickOutCols){
            pickOutCol(length, height, matr, isTurned, firstToSwap - 1, BACKGROUND_GREEN);
            pickOutCol(length, height, matr, isTurned, secondToSwap - 1, BACKGROUND_RED);
            toPickOutCols = 0;
        }

        toSwitch = 0;
        setTextLine(1, y + 2, "Enter your command:",  FORE_WHITE);
        do{
            getText(1, y + 3, entred, BACK_BLACK, FOREGROUND_GREEN);
        }while(entred[0] == '\0');

        strcpy(cpy, entred);
        g = strtok(cpy, " ");
        if(!g)
            g = "\n";
        for(i = 2; i < COLS; i++){
            moveCursor(i, y + 3);
            putchar(' ');
        }
        if(!strcmp(entred, "help")){
            helpComm(y + 5);
            help = 1;
        }else if(!strcmp(entred, "clear all")){
            clearMatr(length, height, matr);
            color = FIELD_BACKGROUND | FORE_YELLOW | FOREGROUND_INTENSITY;
        }else if(!strcmp(g, "random")){
            lowVal = -1000;
            highVal = -1000;
            char cpy1[100];
            for(i = 0; cpy[i + 7] != '\0'; i++){
                cpy1[i] = cpy[i + 7];
            }
            cpy1[i] = '\0';
            getPartiedInts(cpy1, &lowVal, &highVal);

            if((lowVal > highVal) || (highVal > 999) || (lowVal < -999)){
                invalidInput(y);
            }else{
                fillRand(length, height, matr, lowVal, highVal);
                color = FIELD_BACKGROUND | FORE_YELLOW | FOREGROUND_INTENSITY;
            }
        }else if(!strcmp(g, "set")){
            cX = -1;
            cY = -1;
            val = -1000;
            char cpy1[100], *l;
            for(i = 0; cpy[i + 4] != '\0'; i++){
                cpy1[i] = cpy[i + 4];
            }
            cpy1[i] = '\0';
            getPartiedInts(cpy1, &cX, &cY);
            l = strtok(cpy1, ":");
            l = strtok(NULL, ":");
            if(l != NULL){
                val = atoi(l);
            }

            if(!isTurned){
                if(cX > length || cX <= 0 || cY > height || cY <= 0 || val > 999 || val < -999){
                    invalidInput(y);
                }else{
                    matr[cY -  1][cX - 1] = val;
                    toYellow = 1;
                }
            }else{
                if(cX > height || cX <= 0 || cY > length || cY <= 0 || val > 999 || val < -999){
                    invalidInput(y);
                }else{
                    matr[cX - 1][cY - 1] = val;
                    toYellow = 1;
                }
            }
        }else if(!strcmp(entred, "print upright")){
            isTurned = !isTurned;
            toSwitch = 1;
        }else if(!strcmp(entred, "middle value")){
            double mid = countMiddle(length, height, matr);
            setTextColor(FORE_WHITE);
            moveCursor(5, y + 4);
            printf("middle value: ");
            setTextColor(FORE_YELLOW);
            moveCursor(22, y + 4);
            printf("%f                         ", mid);
            help = 1;
        }else if(!strcmp(g, "sum")){
            int sum;
            row = -1;
            g = strtok(NULL, " ");
            if(g != NULL && !strcmp(g, "in")){
                g = strtok(NULL, " ");
                if(g != NULL && !strcmp(g, "row")){
                    g = strtok(NULL, " ");
                    if(g != NULL)
                        row = atoi(g);
                }
            }
            if(row < 0 || row > (isTurned ? length : height))
                invalidInput(y);
            else{
                sum = sumInRow(length, height, matr, isTurned, row -1);
                toPickOutRow = 1;
                setTextColor(FORE_WHITE);
                moveCursor(5, y + 4);
                printf("sum in %dth row: ", row);
                setTextColor(FORE_YELLOW);
                moveCursor(22, y + 4);
                printf("%d                         ", sum);
                help = 1;
            }
        }else if(!strcmp(entred, "swap 1")){
            swapMinMax(length, height, matr, isTurned, 1, swaped);
            isSwaped = 1;
        }else if(!strcmp(entred, "swap 2")){
            swapMinMax(length, height, matr, isTurned, 0, swaped);
            isSwaped = 1;
        }else if(!strcmp(entred, "swap cols")){
            swapCols(length, height, matr, isTurned, &firstToSwap, &secondToSwap);
            toPickOutCols = 1;
        }else if(!strcmp(entred, "clean workspace") && help){
            toClean = 1;
            help = 0;
        }else if(!strcmp(entred, "f**k you")){
            clearScr();
            setTextLine(0, 0, "GO F**K YOURSELF!", FOREGROUND_RED | FOREGROUND_INTENSITY);
            setTextColor(FORE_WHITE);
            return EXIT_FAILURE;
        }else if(!strcmp(entred, "exit")){
            clearScr();
            setTextColor(FORE_WHITE);
            return EXIT_SUCCESS;
        }else{
            invalidInput(y);
        }
    }
    return EXIT_SUCCESS;
}