Answer please, which sorting algorithms i can sorting this array:
Field1; 2009-05-11
Field2; 2009-10-20
Field3; 2008-04-07
so, result mst be like this:
Field3; 2008-04-07
Field1; 2009-05-11
Field2; 2009-10-20
Printable View
Answer please, which sorting algorithms i can sorting this array:
Field1; 2009-05-11
Field2; 2009-10-20
Field3; 2008-04-07
so, result mst be like this:
Field3; 2008-04-07
Field1; 2009-05-11
Field2; 2009-10-20
Is this data coming from a database? If so, recommend writing the query to return the fields already sorted -- easier to let the database do it for you.
No, not from db.
This array creating from data in random stream.
Look at this thread by Ellis Dee, plenty of search algos to choose from.
Tip: When sorting, ensure your array is of Date type variables or use CDate() in the sort function
Dear LaVolpe, i saw these examples of sorting, but i can't choose necessary for my challenge.
And also, thanks for Tip!
Show us what your array looks like in code, how is it declared, how many dimensions.
In that link, look at Ellis Dee's last post and maybe use the author's recommendation.
originally, i am such a text file:
this i s little peace of example, the algrtmh of code is very difficult, the array have arr(x,6)Quote:
Publisher:
JSC Venturo
IP Jorney
DateOfPublish:
2001-05-03
2000-01-02
Author:
Smith
John
...
i'm parse data to array:
arr(0,0) = "JSC Venturo"
arr(0,1) = "2001-05-03"
arr(0,2) = "Smith"
arr(1,0) = "IP Jorney"
arr(1,1) ="2000-01-02"
arr(1,2) ="John"
the arr(x, 3 to 6) had other string data
See if Ellis Dee's 2D array sort is what you need?
Global thank you!
Look likes good.
Tommorow, (today morning) try to resolve my problem.
LaVolpe, ezright, the Ellis Dee's 2D array sort fine!
Problem is resolve.
P.S. but, maybe you know how possible sort other columns after first, such in SQL,
for example, ORDER BY f(3), f(2), f(5)
All sorting algorithms can be described as being either stable or unstable.
A stable sorting algorithm will maintain the relative order of equal keys whereas and unstable algorithm might not.
Sorting by more than one column can be very simple with a stable algorithm. Simply sort the whole array by each of the columns you are interested in, starting with the column of least priority, finishing with the column of highest priority. Not exactly efficient, but simple.
Alternatively a solution that works with both stable and unstable algorithms is to start by sorting the column of highest priority, if the sorted column contains any sections of duplicate keys then sort each (if any) of these sections by the next highest priority column. If the next column contains any duplicates then sort these by the column after that...
If an unstable algorithm is used for the above and the final column contains duplicates then these sections might not maintain the original order. If stability is important then another column can be added to store the original order. This column can then be used for the final sort.
It looks like you are using Quicksort which is an unstable algorithm.
The sorting thread already linked to explains a lot more.
i resolve this problem by creating object adodb.recordset, fill rs with my array and apply .sort by 2 fields.