|
-
Aug 25th, 2009, 09:53 AM
#1
Thread Starter
Addicted Member
Sorting array by date
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
-
Aug 25th, 2009, 09:55 AM
#2
Re: Sorting array by date
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.
-
Aug 25th, 2009, 10:15 AM
#3
Thread Starter
Addicted Member
Re: Sorting array by date
No, not from db.
This array creating from data in random stream.
-
Aug 25th, 2009, 10:33 AM
#4
Re: Sorting array by date
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
-
Aug 25th, 2009, 03:19 PM
#5
Thread Starter
Addicted Member
Re: Sorting array by date
Dear LaVolpe, i saw these examples of sorting, but i can't choose necessary for my challenge.
And also, thanks for Tip!
-
Aug 25th, 2009, 03:36 PM
#6
Re: Sorting array by date
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.
-
Aug 25th, 2009, 03:57 PM
#7
Thread Starter
Addicted Member
Re: Sorting array by date
originally, i am such a text file:
Publisher:
JSC Venturo
IP Jorney
DateOfPublish:
2001-05-03
2000-01-02
Author:
Smith
John
...
this i s little peace of example, the algrtmh of code is very difficult, the array have arr(x,6)
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
-
Aug 25th, 2009, 04:02 PM
#8
Re: Sorting array by date
See if Ellis Dee's 2D array sort is what you need?
-
Aug 25th, 2009, 04:10 PM
#9
Thread Starter
Addicted Member
Re: Sorting array by date
Global thank you!
Look likes good.
Tommorow, (today morning) try to resolve my problem.
-
Aug 26th, 2009, 02:48 AM
#10
Thread Starter
Addicted Member
Re: Sorting array by date
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)
-
Aug 26th, 2009, 05:56 AM
#11
Re: Sorting array by date
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.
-
Aug 28th, 2009, 08:13 AM
#12
Thread Starter
Addicted Member
Re: Sorting array by date
i resolve this problem by creating object adodb.recordset, fill rs with my array and apply .sort by 2 fields.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|