Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,919 questions

51,852 answers

573 users

How to delete the middle element of a stack in VB.NET

1 Answer

0 votes
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
'

 



answered May 27, 2023 by avibootz
...