VBS (ASP) Stack class

Source: Internet
Author: User
Tags join split

With JS can use the array object is very easy to realize the function of the stack, but there is no corresponding function in the VBS, no way, only their own hands: (

If your stack does not understand please check the data structure of the relevant content. This stack class is written in reference to the C + + stack class, using the same usage. With this class you can also easily modify the queue's class:)

<%
'**********************************************
' VBS STACK Class
' Push (string) into stack
' GetTop the top element of the stack
' Pop off stack top element
' IsEmpty whether the stack is empty
' Isfull whether the stack is full (Pmax set size, can be modified by itself)
'
'**********************************************

Class Stack
Private PARR, pstring, Pmax
Private tab
Private Sub Class_Initialize ()
TAB=CHR (9)
pmax=1000 ' max capacity
End Sub
Private Sub Class_Terminate ()
If IsArray (PARR) Then
Erase PARR
End If
End Sub

Public function push (str)
If Str<> "" and InStr (Str,tab) <1 and not Isfull then
If IsArray (PARR) Then
Pstring=join (Parr,tab)
End If
Pstring=pstring & Tab & STR
Parr=split (Pstring,tab)
Push=true
Else
Push=false
End If
End Function

Public Function GetTop ()
If not IsArray (PARR) <0 Then
Gettop=null
Else
If UBound (PARR) <0 Then
Gettop=null
Else
Gettop=parr (Ubound (PARR))
End If
End If
End Function

Public Function Pop ()
If not IsArray (PARR) Then
Pop=false
Else
If Ubound (PARR) <0 Then
Pop=false
Else
Pstring=join (Parr,tab)
Pstring=left (Pstring,instrrev (Pstring,tab)-1)
Parr=split (Pstring,tab)
Pop=true
End If
End If
End Function

Public Function IsEmpty ()
If not IsArray (PARR) Then
Isempty=true
Else
If Ubound (PARR) <0 Then
Isempty=true
Else
Isempty=false
End If
End If
End Function

Public Function Isfull ()
If not IsArray (PARR) Then
Isfull=false
Else
If UBound (PARR) <pmax Then
Isfull=false
Else
Isfull=true
End If
End If
End Function
End Class
%>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.