[.NET] 我的中序轉後序有點問題請問該怎麼改?
程式碼如下
Public Sub turn(ByVal str() As String
Dim i As Integer
For i = 0 And i < str.Length To i + 1
If (Array.IndexOf(sun, str(i)) >= 0 Or (Array.IndexOf(cal2, str(i)) >= 0)) Then
If (str(i) = "*" Or str(i) = "/") Then
While (top > -1 AndAlso (Stack(top) = "*" Or Stack(top) = "/"))
sol += pop(i)
push(str(i))
End While
ElseIf (str(i) = "+" Or str(i) = "-") Then
While (top > -1 AndAlso (Stack(top) = "*" Or Stack(top) = "/"))
sol += pop(i)
End While
While (top > -1 AndAlso (Stack(top) = "+" Or Stack(top) = "-"))
sol += pop(i)
End While
push(str(i))
Else
push(str(i))
End If
ElseIf (Array.IndexOf(cal3, str(i)) >= 0) Then
While (Stack(top) <> "(")
sol += pop(i)
End While
top = top - 1
Else
sol = sol + str(i)
End If
While (top > -1)
sol += pop(i)
End While
Console.WriteLine(sol)
Next
end sub
Sub demo_test()
Dim t1 As test
Dim sol = " "
Dim enter As Integer
Console.WriteLine("**************************************************")
Console.WriteLine("** 中序轉後序 **")
Console.WriteLine("**************************************************")
Console.Write("請輸入中序式:")
Dim input As String = Console.ReadLine()
t1.turn(input)
^^^^^^^^^^^^^^^
Console.ReadLine()
End Sub
只是擷取程式片段,還不確定程式能跑,
一直卡在t1.turn(input)這行,說無法轉換string的值
老師說把Public Sub turn(ByVal str() As String)的str()括號拿掉
但是裡面程式中的str(i)就會有問題了!
不曉得該怎麼改,第一次學.net,有點頭大,先謝謝唷!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 203.73.7.242
Visual_Basic 近期熱門文章
PTT數位生活區 即時熱門文章