Imports System
Imports System.Collections.Generic
Public Class Program
Public Shared Sub deleteMiddleElement(ByVal st As Stack(Of Char), ByVal size As Integer, ByVal Optional current As Integer = 0)
If st.Count = 0 OrElse current = size Then
Return
End If
Dim el As Char = st.Peek()
st.Pop()
deleteMiddleElement(st, size, current + 1)
If current <> size \ 2 Then
st.Push(el)
End If
End Sub
Public Shared Sub Main(ByVal args As String())
Dim st As Stack(Of Char) = New Stack(Of Char)()
st.Push("3"c)
st.Push("5"c)
st.Push("1"c)
st.Push("m"c)
st.Push("9"c)
st.Push("2"c)
st.Push("7"c)
deleteMiddleElement(st, st.Count)
For Each item In st
Console.WriteLine(item)
Next
End Sub
End Class
' run:
'
' 7
' 2
' 9
' 1
' 5
' 3
'