How to find duplicates in an array and remove them
efficiently?

Answers were Sorted based on User's Feedback



How to find duplicates in an array and remove them efficiently?..

Answer / vishnu


Dim a(4)

a(0) = 1
a(1) = 4
a(2) = 5
a(3) = 4
a(4) = 5

For i = ubound(a)-1 to 0 step - 1
For j=0 to i
If a(j) = a(j+1) Then
a(j) = empty
ElseIf a(j)>a(j+1) Then
temp = a(j+1)
a(j+1) = a(j)
a(j) = temp
End If
Next
Next

For i=0 to ubound(a)
print a(i)
Next

Is This Answer Correct ?    1 Yes 0 No

How to find duplicates in an array and remove them efficiently?..

Answer / crazy boy

**How to find duplicates in an array and remove them efficiently?
=================================================
dim a(4)
a(0)=10
a(1)=20
a(2)=10
a(3)=20
a(4)=50

for i=0 to ubound(a)
for j=i+1 to ubound(a)
if a(i)=a(j) then
a(i) =empty
end if
next
next

for i=0 to ubound(a)
if a(i)<>"" then
msgbox a(i)
end if
next

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More QTP Interview Questions

when to start the automation?

0 Answers   Accenture,


What is the use of sendkeys.In which cases we Use this sendkey.Pls explain with example.

3 Answers   Cap Gemini,


QTP Data Table Having 10 records with 10 to 15 fields(lets say).now i want to get alternative records from datatable.pls can any one answer it?

3 Answers   Syntel,


somebody please say me why we go for using regular expressions,actions.what is the main and exact use of this in real time applications.real time testers pls answer my question with example if u can

4 Answers  


What is the DIFF Between PROJECT AND PRODUCT?When Company will need Product?

5 Answers  


Could you please suggest a book to start with QTP and also a book for advanced concepts?

2 Answers  


what is object and child object.. explain ..if possible give some example for better understanding ..

0 Answers   HCL,


give me the code to save all messages of inbox of gmail into a folder and notepad

0 Answers   Infosys,


1) 100 test boxes there in application. how to click 100 test boxes using vb script? 2) 100 objects there in web page,how we will store that 100 objects repostries?

3 Answers   ANZ,


in one page we have 100 links i have to click the 99th link how can i click the 99th link.

4 Answers   GK Technologies, IBM,


How can I replace all the text from the QTP script with some other text. Is there any replace all function in QTP Any one can help me

5 Answers   Livetek, Virtusa,


you written some code in qtp for opening google.com browser and entered some text inthe search text box and clicked search button. this is ur script.. before running this script i have already opened two google.com browsers. now am running the script what will happen? script will run or what?? Thanks... Nani

4 Answers   Oracle,


Categories