AutoHotkey Community

It is currently May 26th, 2012, 3:10 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: bubble sort an array?
PostPosted: March 3rd, 2009, 11:52 pm 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 4th, 2009, 1:13 am 
Offline

Joined: August 2nd, 2008, 12:31 am
Posts: 101
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


Report this post
Top
 Profile  
Reply with quote  
PostPosted: March 4th, 2009, 12:50 pm 
Offline

Joined: July 31st, 2008, 10:27 pm
Posts: 336
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
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 4th, 2009, 1:13 pm 
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]


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 4th, 2009, 11:15 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
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.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: G. Sperotto, nyoe, patgenn123, Tilter_of_Windmills, Yahoo [Bot] and 21 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group