數(shù)據(jù)結構(9.13)

1.求算術表達式的值

others' mentality

first, find out the suffix expression.

put the string in an array and named as exp, and define another array named postexp, which is to put the suffix expression. The two arraies are typed of char. ?In order to make the trance come true, a operation stack?is necessary.?A stack is named as?op to stor the operations in the original expression.?To follow the rule of caculation, we need to define the primary of the opertaions as the following?table.?ps.the lpri means the char from the exp in the process of traversal. the rpri is the char in the op.

if the leftpri's primary is higher than the right one, which means that the operation should be poped from the op and putted into the postexp; else if the leftpri's primaty is lower than the right one, which means that the operation?was put into?op and the traversal?goes on. else,?get out all the?left operations in the op in order and put them in?the postexp. The postexp is the?suffix expersion of the orgiainal expression.

Second, do operation with the postexp.

A number stack is necessary, which is to put the result of each stp of operation.

Traversal op and when meet numbers get out and get it stored in?the stack?and when meet an operation, get out two numbers from the number stack and do the operation with the numbers that you get out from the stack and put the result back to the stack untile the postexp is traversaled over.

Code written?with the help of?book


5.Summary

stray \241??or ?\243?in program means that there are Chinese input

When I get a problem, I should be clam down and try to find the solution with the knowledge that I have learnt, just to try it.

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

  • **2014真題Directions:Read the following text. Choose the be...
    又是夜半驚坐起閱讀 11,097評論 0 23
  • 她在傍晚的冷風裡等105路公交車。路上行人稀少,她裹緊了衣服在風中打了個冷戰(zhàn)。已是三月末的天氣,不該這樣冷。她無聊...
    連生閱讀 291評論 0 0
  • 離家的公交車上,不斷搖曳,抖抖停停,搖出了一些記憶片段,那些消逝的,即將消失的斑駁的舊時光。望著車窗外變遷的田野,...
    辰北閱讀 322評論 0 0
  • 字符串轉data型 data轉string型 變化的我都懵逼了,有興趣的可以記一下
    寧靜1致遠閱讀 24,411評論 0 6

友情鏈接更多精彩內容