Sign in to follow this  
Followers 0
Guest slimshacaca

Arrange Array Smallest to Largest HELP

4 posts in this topic

I am currently using AutoIt v3.0.102...

And i need help or guidence on how i can arrange an arry of numbers from smallest to largest while the end result is still an arry...

EX: 15|14|22|02|20|01|33

I need help taking that to: 01|02|14|15|20|22|33

Please help :">

Share this post


Link to post
Share on other sites



I am currently using AutoIt v3.0.102...

And i need help or guidence on how i can arrange an arry of numbers from smallest to largest while the end result is still an arry...

EX:  15|14|22|02|20|01|33

I need help taking that to:  01|02|14|15|20|22|33

Please help  :">

<{POST_SNAPBACK}>

you may want to check out a few of the results I pulled up on a search for "bubble sort":

http://www.autoitscript.com/forum/index.ph...findpost&p=5930


"I'm not even supposed to be here today!" -Dante (Hicks)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Bubblesort is the best, but here is a slow way to do it with arrays.

$array1=StringSplit("15|14|22|02|20|01|33","|")
$array2=$array1
Dim $arrayout[$array1[0]+1]
$arrayout[0]=$array1[0]

$x=1
for $h=1 to $array2[0]
for $i=1 to $array2[0]
if number($array2[$x])>number($array2[$i]) then $x=$i
next
$array2[$x]=999999999
$arrayout[$h]=$array1[$x]
next

; array display
$x=""
for $i=1 to $arrayout[0]
$x=$x & "|" & $arrayout[$i]
next
$x=StringTrimLeft($x,1)

msgbox(1,"list",$x)

Quick and dirty, and I should redim and stuff, but you can see the output. :)

For use I would go bubblesort.

edit.. just FYI since I wrote over each item in the output array, you could replace:

Dim $arrayout[$array1[0]+1]
$arrayout[0]=$array1[0]

with

Dim $arrayout=$array1

This is more of a teaching script than anything, although it works.

Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

Thank you both for your assistance, answered my question perfectly and enlightened me in a new way to look at the array system in AutoIt.

Thanks muches

Slim

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0