Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old May 1st, 2003, 08:39 AM
NAVData NAVData is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Location: Vienna, Austria
Posts: 3 NAVData User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to NAVData
multiple sorting of an array

Hi,
i search a possibility to sort an array with more than one key (like an ORDER BY X, Y in SQL). I have searched the whole internet after this information, but without any help ...

I have a random-file, with more than 200.000 records. The quicksort-routine for one key is very fast and no problem. But i need more: I have 3 values

ID,LAT,LONG

And now i want to sort the LAT AND!!! the LONG values tougether, because some LAT values are equal.

Hope i found here a answer of my question ... and a solution of my project (which is stopped since over a week, due this problem )

Thanks,
Richard

Reply With Quote
  #2  
Old May 1st, 2003, 08:54 AM
Onslaught's Avatar
Onslaught Onslaught is offline
/(bb|[^b]{2})/
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Nov 2001
Location: Somewhere in the great unknown
Posts: 4,829 Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Day 23 h 5 m 8 sec
Reputation Power: 88
Send a message via ICQ to Onslaught
I would imagine that you would have to create your own sort routine.

The easiest solution would be to use a database for this instead of a flat file.

Reply With Quote
  #3  
Old May 1st, 2003, 09:01 AM
NAVData NAVData is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Location: Vienna, Austria
Posts: 3 NAVData User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to NAVData
Hi Onslaught,
yes, i know! I know that a database handles this correctly and i know how i can do this. My problem is, that iīm working on a project, where i canīt use any databases or 3rd party addons to sort this datas. I must do it by myself - but how??

I have made many experiments with different sort-algorithms, but i havenīt found any solution for my problem. I donīt need a complete program code, i only need a idea, how i can realize this problem.

I see no way to solve it by myself ...
Richard

Reply With Quote
  #4  
Old May 1st, 2003, 09:31 AM
Onslaught's Avatar
Onslaught Onslaught is offline
/(bb|[^b]{2})/
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Nov 2001
Location: Somewhere in the great unknown
Posts: 4,829 Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Day 23 h 5 m 8 sec
Reputation Power: 88
Send a message via ICQ to Onslaught
Ok, lets brake this down.
Lets look at this from the easiest sorting solution. You already know how to sort on one field easily enough, lets take that knowledge and apply it to multiple fields but, for a twist, do it as only one field.
When you apply the sorting logic to the field, combine all of the ordering fields together into one string, delimited by whatever fashion you want, and send that to the sorting function.

Does that make sense?

Reply With Quote
  #5  
Old May 9th, 2003, 09:21 AM
thomasp thomasp is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Location: Cyprus
Posts: 4 thomasp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally posted by Onslaught
Ok, lets brake this down.
Lets look at this from the easiest sorting solution. You already know how to sort on one field easily enough, lets take that knowledge and apply it to multiple fields but, for a twist, do it as only one field.
When you apply the sorting logic to the field, combine all of the ordering fields together into one string, delimited by whatever fashion you want, and send that to the sorting function.

Does that make sense?


In principle I agree with Onslaught but it is probably more ilegant and flexible to use a different function that will get the three (or actually the n) fields and return a single sort sequence value. One such function is what Onslaught is saying i.e. simply concanating the three values.

In pseudo code most sorting algorithms look like something like this


loop
compare (a,b)
re-order list according to results of comparison
end loop

where a,b are the values that are to being compared i.e. in most cases the values of some fields.

There is nothing prohibiting of changing that to the return values of some functions.
i.e. a = valueOf(a1,a2,...an)
b = valueOf(b1,b2,....bn)

valueOf can simply be a string concunacation or even something quite complex e.g. non-linear functions e.t.c

Hope this helps more

Thomas

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > multiple sorting of an array


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway