I'm using MS to sort the contents of a .csv file, I found a quick and simple method in one of the posts, the bubble sort algorithm. It works well with small lists, but is not practical for large lists.
I tried using excel, but it messes up .csv files on saving. Besides, I sometimes need to review the results while its working and that causes file access errors.
I would appreciate it if someone would help me create a function that performs quicksort algorithm. More info and pseudo code is at: http://en.wikipedia.org/wiki/Quicksort
If there's an alternative native function in windows API or some DLL that I could download, I'd appreciate it if someone could point me in the right direction and show me how to integrate it into my macro.
Thank you for an excellent product.
Exchange Sort, Insert Sort, or Quicksort?
Moderators: JRL, Dorian (MJT support)
-
- Newbie
- Posts: 1
- Joined: Thu Oct 22, 2009 2:09 pm
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
I adapted the non-recursive Quicksort PHP function found here:
http://www.algorithmist.com/index.php/Q ... ursive.php
http://www.algorithmist.com/index.php/Q ... ursive.php
Code: Select all
GetFileList>%WIN_DIR%\*.*,files
Separate>files,;,array
/*
Let>array_1=Yellow
Let>array_2=Apple
Let>array_3=Blue
Let>array_4=White
Let>array_5=Azure
Let>array_count=5
*/
If>array_count>0
Let>cur=1
Let>stack[1]['l']=1
Let>stack[1]['r']=array_count
Repeat>cur
Let>l=stack[%cur%]['l']
Let>r=stack[%cur%]['r']
Let>cur=cur-1
Label>lloop
Let>i=l
Let>j=r
Let>pivot={(%l%+%r%) div 2}
Let>tmp=array_%pivot%
Label>iloop
Label>left
Let>this=array_%i%
If>{%this%<%tmp%}
Let>i=i+1
Goto>left
Endif
Label>right
Let>this=array_%j%
If>{%tmp%<%this%}
Let>j=j-1
Goto>right
Endif
If>{%i%<=%j%}
Let>w=array_%i%
Let>array_%i%=array_%j%
Let>array_%j%=w
Let>i=i+1
Let>j=j-1
Endif
If>{%i%<=%j%},iloop
Endif
If>i<r
Let>cur=cur+1
Let>stack[%cur%]['l']=i
Let>stack[%cur%]['r']=r
Endif
Let>r=j
If>l<r,lloop
Endif
Until>cur=1
Endif
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
-
- Newbie
- Posts: 18
- Joined: Thu Feb 06, 2014 5:19 pm
Re: Exchange Sort, Insert Sort, or Quicksort?
Just a heads up, I think you want the loop termination condition to be:
Code: Select all
Until>cur=0