Implementation principle of express opener (fast priority)

zhaozj2021-02-11  233

INT SCAN (Char * SRC, FLOAT * NUM, CHAR * SIGN, INT * Level) {INT Count = 0, stdlevel = 0; While (* src) {if (* src == '(') stdlevel = 2; if (* src == ')') stdlevel- = 2; if (* src == ' ' || * src == '-') {sign [count] = * src; level [count] = stdlevel;} IF (* src == '*' || * src == '/') {sign [count] = * src; level [count] = stdlevel 1;} if (* src> = '0' && * src <= '9') {NUM [count] = 0; while (* src> = '0' && * src <= '9') {Num [count] = NUM ​​[count] * 10 * src-'0 '; SRC ;} count ; src--;} src ;} return count;} Float Exp (INDEX, FLOAT * NUM, CHAR * SIGN, INT * Level) {INT K; Float Mid, Left, Right; IF Index <2) MID = NUM ​​[0]; ELSE IF (INDEX <3) {Left = NUM ​​[0]; Right = Num [1]; k = 1;} else {int min = 25536, d; k = index -1; for (D = index-1; D> 0; D -) IF (min> level [d]) {min = level [d]; k = d;} if (k> = 2) Left = Exp (K, Num, Sign, Level); Else Left = NUM ​​[K-1]; if (INDEX-K> = 2) Right = Exp (INDEX-K, NUM K, SIGN K, Level K) Else Right = NUM ​​[INDEX-1];} Switch (Sign [K]) {CASE ' ': MID = Left Right; Break; Case '-': MID = Left-Right; Break; Case '*' : MID = Left * Right; Break; Case '/': MID = Left / Right; Break;} Return MID;} main () {cha R Sign [100], * SRC = "1 2 * (2 * (5-2) -4) / 2"; / * "(1 2) * 3- (4-5 * (6 / (7) 8) -9)) * 10-11 / 12 "; * / int count = 0, K, Level [100]; float num [100], last; count = scan (src, num, sign, level); Last = Exp (count, NUM, SIGN, Level); CLRSCR (); Printf ("/ NLAST =% 6.2F", LAST); for (k = 0; k

Printf ("% 3.0f", NUM [K]); if (k> = count-1) Continue; gotoxy (k * 5 5, 5); Printf ("% 1c", SIGN [K 1]) Gotoxy (k * 5 4, 6); Printf ("% 2D", Level [K 1]);} getCH ();}

转载请注明原文地址:https://www.9cbs.com/read-5564.html

New Post(0)