Sorting Array of PAIRS

I have an array the needs to be sorted by A().LEFT and then within that A().RIGHT
this array can have 3-4 THOUSAND entires (depending)… basically it is a dictionary of words and page #'s

I have a “bubble” sort that does it… but it starts to slow down alot when you get into larger values.

Radix sort which is stable

Before implementing your own algorithm, what about creating an index array like

index() = A().Left + Str( A().Right, "00000000" )

Then use SortWith?

[quote=70295:@Kem Tekinay]Before implementing your own algorithm, what about creating an index array like

index() = A().Left + Str( A().Right, "00000000" )

Then use SortWith?[/quote]

  dim xsort(-1) as string
  for i=0 to index_data.Ubound
    xsort.append index_data(i).left+"**"+index_data(i).right
  next i
  xsort.SortWith(index_data)

a bit more over head… but dang it it faster than any other method I tried…

I was just about to tell you that I tested this, and it came in at about 37 ms for 5,000 entries. :slight_smile:

You have to use Format or Str with a format for the number, though. Otherwise you’ll get sorts like 1, 10, 11, 2.

Yes… fortunatly my data was already formatted that way :slight_smile: thank