Implementation of Stack using QTP (VBSCRIPT)
Class Stack
Public sizeofStack ' Property/Public variable to hold the index value of Stack Array Public StackLifo() ' Array to hold the values in Stack 'Initialise the size of STack i.e. StackArry by the value passed as Parameter Public Property Let StackSize(ByVal stack_size) sizeOfStack=stack_size ReDim Preserve StackLifo(sizeOfStack) End Property 'Function to Add value to Stack Array Public Function Push(ByVal itemtoPush) For start=0 to Ubound(StackLifo) stackVal=StackLifo(start) If IsEmpty(stackVal) Then StackLifo(start)=itemtoPush [Link] micDone,"STACK ITEM PUSHED","ITEM:::"&chr(34)&StackLifo(start)&chr(34)&", pushed at STACK POSITION::;"&start&", successfully" Exit function ElseIf Not(IsEmpty(StackLifo(Ubound(StackLifo)))) Then [Link] micDone,"STACK LIMIT REACHED","STACK LIMIT IS = "&sizeOfStack&" ITEM :::"&chr(34)&StackLifo(Ubound(StackLifo))&chr(34)&", ALREADY PRESENT"&_ "AT STACK POSITION::;"&Ubound(StackLifo)&", SO UNABLE TO PUSH FURTHER."
Exit Function End If Employee-Personal
Next
End Function
'Function to Pop value from Stack Public Function Pop()
For last=Ubound(StackLifo) to Lbound(StackLifo) step-1 If IsEmpty(StackLifo(last)) Then 'do nothing Else Pop=StackLifo(last) [Link] micDone,"STACK ITEM POPPED","LAST ITEM IN STACK:::"&chr(34)&StackLifo(last)&chr(34)&",STACK POSITION::;"&last&". ITEM POPPED SUCCESSFULLY" StackLifo(last)=Empty Exit Function End If Next
End Function
'Function to Peek value from Stack Public Function Peek()
For last=Ubound(StackLifo) to Lbound(StackLifo) step-1 If IsEmpty(StackLifo(last)) Then
Employee-Personal
'do nothing Else Peek=StackLifo(last) [Link] micDone,"STACK ITEM PEEKED","LAST ITEM IN STACK:::"&chr(34)&StackLifo(last)&chr(34)&",STACK POSITION::;"&last&". ITEM PEEKED" 'StackLifo(last)=Empty Exit Function End If Next
End Function End Class
Dim stackObj Set stackObj=new Stack [Link]=6 '[Link] "Gajendra","samiksha", "sanjay",3,4,5,"Vijay" [Link]("Sharma") [Link]("Vivek") [Link]("Bhavna") [Link](55)
peekItem=[Link]
removedORPopItem=[Link]
Employee-Personal
newPeek=[Link]
[Link]("SAMIKSHA")
[Link]("ROHIT") Pagain=[Link] pop1=[Link] pop2=[Link] peek1=[Link]
[Link]("SANJAY") [Link]("RAJIV") [Link]("00000") [Link](5555555555555555) [Link](22222)
Set stackObj = Nothing
Employee-Personal