Stack data structure in VB.net
By: Issac
Stack is another useful data structure in VB.net which is based upon push-pop method. It works on LIFO mechanism, the last value inserted will be the first one to be removed.
Syntax of Stack push and pop operations
Push: to add an item in the stack datastructure
Syntax: Stack.Push (Object)
Pop: to return the item last inserted item in the stack
Syntax: Stack.Pop ()
Return: the last object in the Stack
Contains: to Check whether an object is in the stack or not
Syntax: Stack.Contains (Object)
VB.NET SourceCode
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click
Dim stackTable As New Stack
stackTable.Push("1")
stackTable.Push("2")
stackTable.Push("3")
stackTable.Push("4")
stackTable.Push("5")
stackTable.Push("6")
stackTable.Push("7")
If stackTable.Contains("4") Then
MsgBox(stackTable.Pop())
Else
MsgBox("not exist")
End If
End Sub
End Class
When you run this program it numbers 1 to 7 (items) into the sack and then checks whether item “4†exists in the stack or not if it exists then the last item added is popped out(7 is popped out) if you check contains with 8 (i.e If stacktable.contains(“8â€) ) then it will say not exist.
Archived Comments
1. How about using stack in microprocessor subj.??? do you have any idea how to push and pop only???
View Tutorial By: Private at 2015-08-18 01:43:18
Comment on this tutorial
- Data Science
- Android
- AJAX
- ASP.net
- C
- C++
- C#
- Cocoa
- Cloud Computing
- HTML5
- Java
- Javascript
- JSF
- JSP
- J2ME
- Java Beans
- EJB
- JDBC
- Linux
- Mac OS X
- iPhone
- MySQL
- Office 365
- Perl
- PHP
- Python
- Ruby
- VB.net
- Hibernate
- Struts
- SAP
- Trends
- Tech Reviews
- WebServices
- XML
- Certification
- Interview
categories
Related Tutorials
Using Resume Next and Resume Line in VB.net
Using On Error GoTo 0 in VB.net
Getting an Exception's Number and Description in VB.net
Raising an Exception Intentionally in VB.net
Exception Filtering in the Catch Block in VB.net
Using Multiple Catch Statements in VB.net
Throwing an Exception in VB.net
Throwing a Custom Exception in VB.net
Changes in Controls from VB6 to VB.net
Unstructured Exception Handling in VB.net