0% found this document useful (0 votes)
97 views

Implementation of Stack in QTP (VBscript)

This document implements a stack data structure using VBScript. It defines a Stack class with methods to initialize the stack size, push items onto the stack, pop items off the stack, and peek at the top item. The class uses an array to store stack items and tracks the current size. The methods perform bounds checking and report events when items are added or removed from the stack. Sample code demonstrates using the class by initializing a stack, pushing and popping various data types onto it, and peeking at items.

Uploaded by

gajendraks79
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
97 views

Implementation of Stack in QTP (VBscript)

This document implements a stack data structure using VBScript. It defines a Stack class with methods to initialize the stack size, push items onto the stack, pop items off the stack, and peek at the top item. The class uses an array to store stack items and tracks the current size. The methods perform bounds checking and report events when items are added or removed from the stack. Sample code demonstrates using the class by initializing a stack, pushing and popping various data types onto it, and peeking at items.

Uploaded by

gajendraks79
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

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 Reporter.ReportEvent 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 Reporter.ReportEvent 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) Reporter.ReportEvent 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) Reporter.ReportEvent 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 stackObj.StackSize=6 'stackObj.Push "Gajendra","samiksha", "sanjay",3,4,5,"Vijay" stackObj.Push("Sharma") stackObj.Push("Vivek") stackObj.Push("Bhavna") stackObj.Push(55)

peekItem=stackObj.Peek

removedORPopItem=stackObj.Pop

Employee-Personal

newPeek=stackObj.Peek

stackObj.Push("SAMIKSHA")

stackObj.Push("ROHIT") Pagain=stackObj.Peek pop1=stackObj.Pop pop2=stackObj.Pop peek1=stackObj.peek

stackObj.Push("SANJAY") stackObj.Push("RAJIV") stackObj.Push("00000") stackObj.Push(5555555555555555) stackObj.Push(22222)

Set stackObj = Nothing

Employee-Personal

You might also like