 
New Member
Get numbers inside all webelements in webtable and sort them Hello guys,
I have attended QTP interview @broadridge hyd he asked me this question
webtable was there 3 rows 3 columns inside webtable all are webelemnts and 9 numbers(3,1,9,4,7,2,6,5,8) were there inside these webelements.we have to retrieve all these 9 numbers and sort them.
I have written this below code please check once and let me now anything wrong and if any better solutions for this.
set wb=browser().page().webtable()
rc=wb.rowcounnt
For i = 1 To rc
cc=wb.columncount(i)
For j = 1 To cc
txt=wb.childitem(i,j,"Webelement",0).getroproperty ("innertext")
a=a&txt&";"
Next
Next
b=split(a,";")
For i=0 To ubound(b)
For j=0 To ubound(b)
If strcomp(b(i),b(j),1) < 0 Then
temp = b(i)
b(i)=b(j)
b(j)=temp
End If
Next
Next
For i=0 To ubound(b)
msgbox b(i)
Next 
SQA Knight
Pradeep,
Can you use the '[code]' blocks? I cannot read without the indentation.
It looks like a reasonable answer to me.
Thanks,
Kevin When in Florida, Don't Tampa with the code. I made this up. 
SQA Knight
In programming, you'll hear something called BigO complexity. So your current algorithm with the nested For loops that run up to the number of elements is considered O(n^2), where N is the number of elements, and all the constants are removed from the equation. https://en.wikipedia.org/wiki/Big_O_notation Basically, in the worst case scenario, you're running for every N elements, C*N number of instructions, Cn^2, simplified as just O(n^2)
There are 2 computer science concepts that'll improve your runtime.
The first concept is optimizing the algorithm to avoid revisiting elements you have already compared. Quicksort if a famous algorithm in this space. https://en.wikipedia.org/wiki/Quicksort Quick sort will get you down to O(n log n)
The 2nd concept is using advanced data structures that uses references to avoid recopying values. Currently you're using arrays, where you have to waste 3 instructions to copy the data to a temp value, then back to its new destination. Data structures such as linked lists and trees allow you to simply insert an element at it's intended destination without recopying. A famous algorithm in this space is the Binary search tree, https://en.wikipedia.org/wiki/Tree_sort This will also get your a O(n log n). There are variations of this that work better with large data sets such as the BTree, https://en.wikipedia.org/wiki/Btree
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules 