数据结构代码 中缀转后缀表达式算法及源代码(国外英文资料).docVIP

  • 2
  • 0
  • 约9.59千字
  • 约 27页
  • 2017-06-08 发布于河南
  • 举报

数据结构代码 中缀转后缀表达式算法及源代码(国外英文资料).doc

数据结构代码 中缀转后缀表达式算法及源代码(国外英文资料)

数据结构代码 中缀转后缀表达式算法及源代码(国外英文资料) # include stdio, h # include stdlib. H H # include math.h # define MAX 100 / * expressions maximum length * / 1 # define true # define false 0 / * define the data stack * / Typedef struct LinkStack1 { Float data; Struct LinkStack1 * next; } LinkStack1, * Top1; Int initStack1 (Top1 * t) / * data stack initialization * / { * t = NULL; Return true; } Int push1 (Top1 * t, float val) / * data stack inserts elements * / { Top1, p = (Top1) malloc (LinkStack1); / * open memory * / If (p = = NULL) Return false; P - data = val. P - next = * t; * t = p; Return true; } Float getTop1 (Top1 * t) / * fetching data stack element * / { Return (* t) - data; } Int pop1 (Top1 * t, float * val) / * push the data stack element to * val * / { Top1 p = * t; If (p = = 0) Return false; * t = p - next; * val = p - data; Free (p); / * release the memory * / Return true; } / * define operator stack * / Typedef struct LinkStack2 { The int data; Struct LinkStack2 * next; } LinkStack2, * ranked by; Int initStack2 (Top2 * t) / * data stack initialization * / { * t = NULL; Return true; } Int push2 (Top2 * t, char val) / * operator stack inserts elements * / { Top2 is (Top2) malloc (LinkStack2); / * open memory * / If (p = = 0) Return false; P - data = val. P - next = * t; * t = p; Return true; } Int getTop2 (Top2 * t) / * extract operator stack element * / { Return (* t) - data; } Int pop2 (Top2 * t, char * val) Ranked by p = * t; If (p = = 0) Return false; * t = p - next; * val = p - data; Free (p); / * release the memory * / Return true; } / * computing * / Float c (float a, char op, float b) {int d, e; The switch (op) { Case + : return a + b; / * computing + * / Case - : return a-b; / * computing - * / Case : return a * b; / * computing * * / Case / : / * calculation /, if the number is zero, the report is wrong * / If (b = = 0) { Printf ( Error Divisor is 0 \ n ); Return false; } Return a/b; Case % : / * calculate %, if you are left with zero error *

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档