Imports System.Collections

Public Class Stack
  Private stk As ArrayList

  Public Sub New()
    MyBase.New()
    stk = New ArrayList()
  End Sub
  '----------------------------------------
  Public Sub push(ByVal obj As Object)
    stk.Add(obj)
  End Sub
  '----------------------------------------
  Public Function pop() As ParseObject
    Dim obj As Object = CType(stk(stk.Count - 1), ParseObject)
    Dim i As Integer = stk.Count - 1
    stk.RemoveAt(i)
    Return CType(obj, ParseObject)
  End Function
  '----------------------------------------
  Public Function top() As ParseObject
    Dim obj As Object
    obj = stk(stk.Count - 1)
    Return CType(obj, ParseObject)
  End Function
  '----------------------------------------
  Public Function hasMoreElements() As Boolean
    Return (stk.Count > 0)
  End Function
  '----------------------------------------
  Public Function nextTop() As ParseObject
    Dim i As Integer
    i = stk.Count
    If (i > 1) Then
      Return CType(stk(i - 2), ParseObject)
    Else
      Return Nothing
    End If

  End Function
  '---------------------------------------
  Public Sub pop2Push(ByVal p As ParseObject)
    Dim i As Integer
    i = stk.Count
    If (i >= 2) Then
      pop()
      pop()
      push(p)
    Else
      push(p)
    End If
  End Sub

End Class
