0
我嘗試建立的程序,可以計算堆棧數 但我有一些卡住。 讓我們來看看我的工作方案第一什麼是最好的方法來分開運營商和數字在c
獲取一個表達方式(1 + 2)* 3
分離和重新安排到 「1 2 + 3 *」
讓他們到這個功能我它會成爲psudocode。
if token is a number
push onto the stack
else if token is an operator
pop operand 1 off the stack
pop operand 2 off the stack
apply the operator
push the result back onto the stack
我想了解如何檢查字符串「1 2 + 3 *」 是什麼做到這一點
對不起我的英語
感謝的最好方式的建議。
通過檢查字符串,你的意思是什麼,究竟是什麼?如果問題是「如何判斷一個字符是數字,操作符還是空格」,則答案是「isdigit」和「isspace」。 – tabstop
我認爲你已經把空格b/t兩個數字,因爲在後綴表示法中,兩個(或更多的操作數)可以作爲'AB +'連續出現,所以應該如何解釋'12'('1','2')或'12'你增加空格嗎? –