Fun VBS feature code VBS STACK class _vbs

Source: Internet
Author: User

The problem of data structure is very important, if you can describe the input and output data structure of a problem, then this question is very promising, the data structure is not the patent of C language, the real data structure is pseudo code. The following stack class is the code I used to collect others, and in fact whenever I consider a program problem, especially a complex one, it should be thought of what kind of data to describe your input and output.

'**********************************************
' 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)
'
' Wooden bird 2002.10.10
' http://www.aspsky.net/
'**********************************************

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

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.