add a function generateLongExpr in stackApp.c(h). Add a comprehensive conclusion on calc infix & catalan.

This commit is contained in:
Shine wOng
2019-12-10 16:36:31 +08:00
parent ac443f791a
commit 59df68904c
4 changed files with 116 additions and 4 deletions

View File

@@ -142,6 +142,22 @@ char* toPostfix(char* infixExpr){
}
return postfixExpr;
}
/*
* @brief : to generate a very long expression in the pattern '1+0*1^(1+0*1^(1+0*1^(......)'
* @args : number of brackets in the expression
* @return: pointer to the long expression
*/
char* generateLongExpr(int n){
char* expr = new char[8 * n + 8];
int pos = 0;
for(int ix = 0; ix != n; ix++, pos += 7)
memcpy(expr + pos, "1+0*1^(", 7);
expr[pos++] = '1';
for (int ix = 0; ix != n; ++ix)
expr[pos++] = ')';
expr[pos] = '\0';
return expr;
}
/*-----------build-in functions----------*/
int readNumber(char* &expr){