implementing stacks in visual basic

meghu
meghu used Ask the Experts™
on
hi all,

can some one let me know how to implement stacks in visual basic?i would be more than happy to have that piece of code.thanks in advance

bye
meghu
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Senior .Net Consultant
Top Expert 2016
Commented:
A stack is nothing more then a array. You always pick the latest item. You can get it using the UBOUND function.
Using a collection might be easier, since you won't have to resize it. Just add items to the collection (they by default are added to the end) and then when popping, just remove the last item using the .Count property. Something like the following which I wrote freehand so it probably doesn't compile.

Class Stack

Private m_col as new collection

Public Sub Push(Value as Variant)
   m_col.add Value
End Sub

Public Function Pop() as Variant
  if m_col.count <> 0 then
     pop = m_col.item(m_col.count)
     pop.remove(m_col.count)
  end if
End Function

End Class

Zaphod.
Éric MoreauSenior .Net Consultant
Top Expert 2016

Commented:
please maintain

Questions Asked 8
Last 10 Grades Given B B C  
Question Grading Record 3 Answers Graded / 3 Answers Received
Author of the Year 2009

Commented:
Hi meghu,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept emoreau's comment(s) as an answer.

meghu, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept THIS comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial