我有关于堆栈的问题(哈希表的对应物)。基本上我知道push和pop方法。但是,当用户输入单词时,任何人都可以告诉我如何处理。所有元音都被删除,只插入列表框中的辅音。
试图研究这个问题但却找不到它。
答案 0 :(得分:0)
回答你问题的第二部分(似乎与队列或堆栈无关):
Dim inputString As String = "Some old harvesters can always have tankards of ale"
Dim vowels As Char() = {"a"c, "e"c, "i"c, "o"c, "u"c}
For Each c As Char In inputString.ToLower()
If Not vowels.Contains(c) Then
'display any constanants in the string
Console.WriteLine(c)
End If
Next
答案 1 :(得分:0)
你可以这样做。当您在文本框中键入它们并将它们放入堆栈时,它会拦截您的击键,当您按下Enter键然后处理它时删除值并将其分配给列表框。如果这不是你所要求的,你需要更清楚一点。
Public Class Form1
Dim myStack As Stack(Of Char) = New Stack(Of Char)
Private Sub processStack(value As Stack(Of Char))
Dim temp As List(Of Char) = New List(Of Char)
Do While value.Count > 0
Dim c As Char = value.Pop
Select Case c
Case "a"c, "e"c, "i"c, "o"c, "u"c
Case "A"c, "E"c, "I"c, "O"c, "U"c
Case Else
temp.Add(c)
End Select
Loop
ListBox1.Items.Add(New String(temp.ToArray))
End Sub
Private Sub TextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress
If Not e.KeyChar = vbCr Then
myStack.Push(e.KeyChar)
Else
DirectCast(sender, TextBox).Clear()
processStack(myStack)
End If
End Sub
End Class