Hi **All**,

Well, from now on, since the **6.5.2** version, we can use the **internal Quick Sort** of N++. Fine !

Globally, the **Quick Sort** and the **Binary Tree** sort, with its specific structure of data, are the **two fastest** sorts algorithms, except some variations like **IntroSort**, based on **Quick Sort** and few others.

But, generally, a **good** sort program use **sort keys**. At present, **N++'s Quick Sort** uses each **entire** line, as a **pseudo sort key**. Here is a **simple** way to **simulate** the use of **sort keys** :-)

Just consider a file, with **different sort keys**, from **1** to **n** :

**L1**characters, from the column**C1**, included**L2**characters, from the column**C2**, included**L3**characters, from the column**C3**, included

and so on, till :

**Ln**characters, from the column**Cn**, included

with the **conditions** :

`C1 < C2 < C3... < Cn`

The **smallest length** of the lines, of this file, is `Cn + Ln - 1`

And suppose that we want to **sort**, according to, __in decreasing order__ :

- the
**third**sort's criteria - the
**first**sort's criteria - the
**nth**sort's criteria

and so on, till, __for example__, :

- the
**fifth**sort's criteria

The **main** idea is to __ add, by juxtaposition, at the very beginning__ of each line, with the help of a

**search/replacement**, in

**regular expression**mode, the

**different sort keys**, in the

**user order**So, __IF all the sort keys are identical for some lines, an implicit sort is, then, made on the remainder of the concerned lines__

To that purpose :

**1)** Create the **Search/Replacement** below :

SEARCH : `^.{C1-C0-1}(.{L1}).{C2-C1-1}(.{L2}).{C3-C2-1}(.{L3})............{Cn-Cn-1-1}(.{Ln})`

REPLACE : ** \3\1\n....\5$0** ( Criteria

**3**then

**1**, then

**n**.... and

**5**, followed by the

**entire search**expression

**$0**)

__ Notes__ :

The value of **C0** is, by convention, equal to **0**. So, if **C1 = 1**, the part ** .(C1-C0-1)** is

**useless**!

The different **Ci** and **Li** must be **changed** by any appropriate **non-zero number**

=> The different **sort keys** are **added, in front of each** line, according to the __ user's preferences__ !

**2)** Execute the **Quick Sort** command

**3)** **Get rid** of the **supplementary** stuff, **added** at the **beginning** of each line, with the **simple** Search/Replacement below :

SEARCH : `^.{L1+L2+L3+....Ln}(.*)`

REPLACE : `\1`

=> The **added temporary** sort keys are **removed** from each line

__ Note__ :

Replace the sum **L1+L2+L3+....Ln** by the **resulting number**

__A concrete example__ :

**Three** sort keys : ( ** C1 = 12, L1 = 8** ) , (

**) and (**

`C2 = 20, L2 = 10`

**)**

`C3 = 37, L3 = 1`

**User Sort order ** : Criteria **3**, then criteria **1** and, finally, criteria **2**

Then :

**1)**

SEARCH `^.{11}(.{8}).{7}(.{10}).{16}(.{1})`

REPLACE : `\3\1\2$0`

**2)**

Execution of the **Quick Sort**

**3)**

SEARCH : `^.{19}(.*)`

REPLACE : `\1`

Hope that it'll be useful to someone !

Cheers,

guy038

Last edit: THEVENOT Guy 2013-12-22