Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "logic.h"
- char *deblank(char* input) //funckja usuwająca spacje z wyrażenia
- {
- unsigned int i, j;
- char *output = input;
- for (i = 0, j = 0; i<strlen(input); i++, j++)
- {
- if (input[i] != ' ')
- output[j] = input[i];
- else
- j--;
- }
- output[j] = 0;
- return output;
- }
- void showExp(char* exp) //funkcja wyświetlająca podane wyrażenie
- {
- for (unsigned int i = 0; i < strlen(exp); i++)
- {
- printf("%c", exp[i]);
- }
- }
- char *combineExp(char* exp, char* stack) //funckja łącząca nowo otrzymane wyrażenie z pozostałością stosu
- {
- unsigned int l1 = strlen(exp);
- unsigned int l2 = strlen(stack);
- for (unsigned int i = l1; i < l1 + l2; i++)
- {
- exp[i] = stack[i - l1];
- }
- return exp;
- }
- char *convertToONP(char* input, char* output, char **stack, int *stack_top) //funckja konwertująca wejściowe wyrażenie na wyrażenie zapisane w ONP
- {
- int dlugosc = strlen(input);
- int x = 0;
- for (int i = 0; i < dlugosc; i++)
- {
- switch (input[i])
- {
- case '(':
- {
- (*stack)[(*stack_top)] = input[i];
- (*stack_top)++;
- break;
- }
- case ')':
- {
- for (; (*stack)[(*stack_top) - 1] != '('; (*stack_top)--)
- {
- output[x] = (*stack)[(*stack_top) - 1];
- x++;
- }
- if ((*stack)[(*stack_top) - 1] = '(')
- (*stack_top)--;
- break;
- }
- case '+':
- {
- while ((*stack_top) > 0 && (*stack)[(*stack_top) - 1] != '(')
- {
- output[x] = (*stack)[(*stack_top) - 1];
- x++;
- (*stack_top)--;
- }
- (*stack)[(*stack_top)] = input[i];
- (*stack_top)++;
- break;
- }
- case '-':
- {
- while ((*stack_top) > 0 && (*stack)[(*stack_top) - 1] != '(')
- {
- output[x] = (*stack)[(*stack_top) - 1];
- x++;
- (*stack_top)--;
- }
- (*stack)[(*stack_top)] = input[i];
- (*stack_top)++;
- break;
- }
- case '*':
- {
- while ((*stack_top) > 0 && (*stack)[(*stack_top) - 1] == '*')
- {
- output[x] = (*stack)[(*stack_top) - 1];
- x++;
- (*stack_top)--;
- }
- (*stack)[(*stack_top)] = input[i];
- (*stack_top)++;
- break;
- }
- case '/':
- {
- while ((*stack_top) > 0 && (*stack)[(*stack_top) - 1] == '/')
- {
- output[x] = (*stack)[(*stack_top) - 1];
- x++;
- (*stack_top)--;
- }
- (*stack)[(*stack_top)] = input[i];
- (*stack_top)++;
- break;
- }
- case '^':
- {
- while ((*stack_top) > 0 && (*stack)[(*stack_top) - 1] == '^')
- {
- output[x] = (*stack)[(*stack_top) - 1];
- x++;
- (*stack_top)--;
- }
- (*stack)[(*stack_top)] = input[i];
- (*stack_top)++;
- break;
- }
- default:
- {
- output[x] = input[i];
- x++;
- break;
- }
- }
- }
- return output;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement