This commit is contained in:
Džubara 2025-01-31 19:20:13 +01:00
parent e7b4ea33f3
commit 80b330f482

View File

@ -26,11 +26,11 @@ double odcitaj(double a, double b) { return a - b; }
double nasob(double a, double b) { return a * b; }
double del(double a, double b) { return a / b; }
double sinus(double x) { return sin(x); }
double cosinus(double x) { return cos(x); }
double odmocnina(double x) { return sqrt(x); }
double mocnina(double zaklad, double exponent) { return pow(zaklad, exponent); }
double logaritmus(double x) { return log(x); }
double sin(double x) { return sin(x); }
double cos(double x) { return cos(x); }
double sqrt(double x) { return sqrt(x); }
double pow(double zaklad, double exponent) { return pow(zaklad, exponent); }
double log(double x) { return log(x); }
// Funkcia na konverziu infixového výrazu na postfixový (Shunting-yard algoritmus)
void infix_na_postfix(const char *infix, char *postfix) {
@ -69,7 +69,9 @@ void infix_na_postfix(const char *infix, char *postfix) {
double vyhodnot_postfix(const char *postfix) {
double stack[100];
int top = -1;
char *token = strtok(strdup(postfix), " ");
char *postfix_copy = malloc(strlen(postfix) + 1);
strcpy(postfix_copy, postfix);
char *token = strtok(postfix_copy, " ");
while (token) {
if (isdigit(token[0]) || (token[0] == '-' && isdigit(token[1]))) {
@ -87,5 +89,6 @@ double vyhodnot_postfix(const char *postfix) {
}
token = strtok(NULL, " ");
}
free(postfix_copy);
return stack[top];
}