⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 p2.h

📁 一个表达式计算器的算法,编译后运行,输出output.txt
💻 H
字号:
/* P2.h */

/* union used to put the operator or digital. */
typedef union
{
	char ch;
	double d;
} data;

/* the operation stack */
typedef struct node
{
	data elem;
	struct node* pNext;
} Stack;

/* atom calculation structure */
typedef struct
{
	double dOperand1;
	double dOperand2;
	char chOperator;
} atomCalcElems;

/* Stack Functions. */
Stack* CreateStack(void);
int IsEmpty(Stack *pStack);
void ClearStack(Stack *pStack);
void Push(data elem, Stack *pStack);
int Fetch(Stack *pStack, data *pData);
int Pop(Stack *pStack, data *pData);

/*--------------------------------------*/
/*   Convert Infix to Postfix.          */
/*   Return value:                      */
/*   0:		succeeded                   */
/*   -1:	ERROR IN INFIX NOTATION;    */
/*--------------------------------------*/
//int ConvertInfixToPostfix(char *pExpression);

int IsDigitalChar(char ch);

int IsOperator(char ch);

/*-------------------------------------------------*/
/*   Compare the two operators' precedence,        */
/*   exclude '(' and ')'.                          */
/*   Return value:                                 */
/*   0:		equal;                                 */
/*   1:		ch1 has the higher precedence;         */
/*   -1:	ch2 has the higher precedence;         */
/*   -2:	not valid operator;                    */
/*-------------------------------------------------*/
int CompareOperatorPrecedence(char ch1, char ch2);

/*-------------------------------------------------------------*/
/*   Calculate the expression.                                 */
/*   Parameter:                                                */
/*   [in] str:                                                 */
/*            Pointer to the expression to be calculated.      */
/*   [out] out_result:                                         */
/*            Pointer to the result of the expression.         */
/*   Return value:                                             */
/*   1:	   Succeeded;                                          */
/*   0:    ERROR IN INFIX NOTATION;                            */
/*-------------------------------------------------------------*/
int Calculate(char *str, double *out_result);

/*------------------------------------------------------------------------------------------------------------*/
/* Push the operator to Operators' Stack and calculate the generated part of the postfix expression as well.  */
/* return value:                                                                                              */
/*    1: succeeded                                                                                            */
/*    0: failed                                                                                               */
/*------------------------------------------------------------------------------------------------------------*/
int PushOperatorWithProcess(char ch, Stack *pOperatorsStack, Stack *pOperandsStack);

/* Do the most basic calculation */
int DoAtomCalc(atomCalcElems elems, double* result);

/* Delete the blanks in the expression. */
void DeleteBlanks(char *str);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -