Exchange Sort, Insert Sort, or Quicksort?

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
azzkicker_9002
Newbie
Posts: 1
Joined: Thu Oct 22, 2009 2:09 pm

Exchange Sort, Insert Sort, or Quicksort?

Post by azzkicker_9002 » Thu Oct 22, 2009 2:21 pm

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.

User avatar
JRL
Automation Wizard
Posts: 3529
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Oct 22, 2009 2:25 pm

I don't have time right now to look into this properly but have you tried DOS sort? Open a command window and type "sort /?" for usage.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Oct 27, 2009 12:16 pm

I adapted the non-recursive Quicksort PHP function found here:
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?

OrangeAndBlue
Newbie
Posts: 18
Joined: Thu Feb 06, 2014 5:19 pm

Re: Exchange Sort, Insert Sort, or Quicksort?

Post by OrangeAndBlue » Fri Oct 03, 2014 9:45 pm

Just a heads up, I think you want the loop termination condition to be:

Code: Select all

Until>cur=0

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts