Micro Focus QTP (UFT) Forums
Swap min val with max in array - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Swap min val with max in array (/Thread-Swap-min-val-with-max-in-array)



Swap min val with max in array - Azharqurahi - 07-23-2014

Hi all,

I want to swap the min value with max value without changing the array element.

Array(10,5,20,35,15)

Thanks in advance


RE: Swap min val with max in array - Ankur - 07-23-2014

Code:
sort = Array(10,5,20,35,15)

smallest = sort(0) 'Assuming
greatest = sort(0) 'Assuming

For i = 1 To UBound(sort)
    
    'Looking for smallest
    If sort(i) < smallest then
        smallest = sort(i)
        small_index = i
    End If
    'Looking for greatest
    If sort(i) > greatest then
        greatest = sort(i)    
        great_index = i
    End If
    
Next

'Swapping Values
sort(small_index) = greatest
sort(great_index) = smallest

'Just confirming
For y = o To 4
    msgbox sort(y)
Next



RE: Swap min val with max in array - Azharqurahi - 07-24-2014

Tahnks a lot Ankur.........

This question ask me a interviewer.

I have taken min and max value but don't know how to swap.

Thanks Again.... Doing grate job Dear