AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

bubble sort an array?

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Jim.Karvo
Guest





PostPosted: Tue Mar 03, 2009 10:52 pm    Post subject: bubble sort an array? Reply with quote

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

PostPosted: Wed Mar 04, 2009 12:13 am    Post subject: Reply with quote

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
View user's profile Send private message
Morpheus



Joined: 31 Jul 2008
Posts: 273

PostPosted: Wed Mar 04, 2009 11:50 am    Post subject: There is no spoon... it is only yourself that bends. Reply with quote

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
View user's profile Send private message
Jim.Karvo
Guest





PostPosted: Wed Mar 04, 2009 12:13 pm    Post subject: Reply with quote

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.. Sad[/code]
Back to top
Lexikos



Joined: 17 Oct 2006
Posts: 7293
Location: Australia

PostPosted: Wed Mar 04, 2009 10:15 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group