后缀表达式转中缀表达式代码如下:
Public Function TrueBackToMid(ByVal strBack As String) As String Dim i As Long Dim opCode() As String ' Stop Dim ops1 As String, ops2 As String, opC As String '计算符表示,【保留】 '初始化堆栈 WorkStack.Clear '保留 '堆栈初始化结束 opCode = Split(strBack, ",") ' Stop For i = 0 To UBound(opCode) If IsSymbolEx(opCode(i)) Then ' Stop op2 = WorkStack.Pop op1 = WorkStack.Pop WorkStack.Push "(" & op1 & opCode(i) & op2 & ")" Else ' Stop WorkStack.Push opCode(i) End If Next i op1 = WorkStack.Pop If Len(op1) > 2 Then op1 = Mid(op1, 2, Len(op1) - 2) End If TrueBackToMid = op1 End Function
其中使用了堆栈类:http://www.cnblogs.com/sunsoftresearch/archive/2013/04/23/3037271.html
还使用了判断字符是否为符号的函数:
Public Function IsSymbolEx(ByVal strs As String) As Boolean IsSymbolEx = True Select Case strs Case "+" Case "-" Case "*" Case "/" Case Else IsSymbolEx = False End Select End Function
有问题欢迎留言