 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Jim.Karvo Guest
|
Posted: Tue Mar 03, 2009 10:52 pm Post subject: bubble sort an array? |
|
|
Hello
I am trying to bubble sort an array, but I can't.. I haven't find any solutions.. is it possible?
Thanks for any info,
JimKarvo |
|
| Back to top |
|
 |
Jex
Joined: 01 Aug 2008 Posts: 101
|
Posted: Wed Mar 04, 2009 12:13 am Post subject: |
|
|
Yes, you just need to remember there are no arrays. Just variables that look like arrays.
Ex:
var_1
var_2
var_3
var_4
var_5
var_6
So this is possible. _________________ Woot.
Please read forum etiquette |
|
| Back to top |
|
 |
Morpheus
Joined: 31 Jul 2008 Posts: 273
|
Posted: Wed Mar 04, 2009 11:50 am Post subject: There is no spoon... it is only yourself that bends. |
|
|
I wrote this to sort windows on a screen based on their X, or Y location.
I don't know if it's a bubble sort, but it was supposed to be fairly quick.
| Code: | Sort:
N2:= Iview - 1 ;Iview contains the number of items to sort
Loop, %N2%
{
min=%A_Index%
Z := A_Index
Z++
ThisLoop:
If (%Sort%%min% < %Sort%%Z%) ;Sort contains the name of the Variable to sort by (X or Y)
min := Z
Z++
if Z<=%Iview%
Goto, ThisLoop
Swap(Title%A_Index%,Title%min%) ; sort Window parameters
Swap(Width%A_Index%,Width%min%)
Swap(Height%A_Index%,Height%min%)
Swap(X%A_Index%,X%min%)
Swap(Y%A_Index%,Y%min%)
}
Return
Swap(ByRef Old, ByRef New)
{
tempvar := Old
Old := New
New := tempvar
} |
|
|
| Back to top |
|
 |
Jim.Karvo Guest
|
Posted: Wed Mar 04, 2009 12:13 pm Post subject: |
|
|
I have an example:
That is take 5 user inputs (for aour example inputs, are numbers)
| Code: |
count = 0
loop, 5
{
count += 1
InputBox, dokimi%count%
} |
Then I want to bubble sort, but I don't know how..
I tryied to use the code of morpheus, but it isn't worked.. [/code] |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 7293 Location: Australia
|
Posted: Wed Mar 04, 2009 10:15 pm Post subject: |
|
|
The easiest way is to build a string with all five inputs, then use Sort:
| Code: | loop, 5
{
InputBox, userinput
dokimi .= userinput "`n"
}
StringTrimRight, dokimi, dokimi, 1 ; remove final `n
Sort, dokimi, N ; Numeric sort
MsgBox % dokimi
| Also note that in your code, the automatic variable A_Index can be used in place of count. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|