Software Design
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreSoftware Design

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:
  #1  
Old November 21st, 2002, 12:20 AM
Outrager Outrager is offline
O.(O.O).O Champion
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2001
Location: New York, NY, USA
Posts: 26 Outrager User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 18 m 5 sec
Reputation Power: 0
Sorting a trip from longest or shortest

I'm doing this project in java that has an array of city objects that stores city names, longitudes, and latitudes and I need to sort it by the shortest trip and longest trip. Using a method I can calculate the distance between 2 cities given their longitude and latitude.
What's the easiest way (efficiency not really needed) to them into the longest and shortest trip?
__________________
iRants.com says, "WH(:O)MP! Wazoink!"

Reply With Quote
  #2  
Old November 21st, 2002, 12:51 PM
M.Hirsch M.Hirsch is offline
Contributing User
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,969 M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 42 m 50 sec
Reputation Power: 184
if efficiency does not matter, brute-force it (for school this probably won´t count!)
i.e. calculate all possible permutations of cities, then calculate the length of the way and then
- if you want to sort by length, search on google for "quicksort".
- if you only want the shortest and longest paths, find them in a single loop.

how many cities are there?

the number of loops max. needed is x.
all permutations for a given number n of cities are calculated as
x=n! = n*(n-1)*(n-2)*...*1

if your cpu can handle this many tries in a "normal" time, this is imho your "easiest" way.
__________________
--
Manuel Hirsch - Linux, FreeBSD, programming, administration articles, tutorials and more.

Reply With Quote
  #3  
Old December 4th, 2002, 10:40 AM
Strike Strike is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2001
Location: Houston, TX
Posts: 383 Strike User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 41 m 27 sec
Reputation Power: 7
Send a message via ICQ to Strike Send a message via AIM to Strike Send a message via Yahoo to Strike
Graphs!

If you want something interesting to study, as well as an efficient way of doing this, then this is pretty much graph theory. It's not the easiest thing in the world, but some find it interesting and it's keyed to this sort of problem. Basically you have a set of vertices (the places) and edges (the distances between the vertices). There's a lot of good stuff on graph theory out there.
__________________
Debian - because life's too short for worrying.
Best. (Python.) IRC bot. ever.

Reply With Quote
  #4  
Old December 4th, 2002, 03:12 PM
riv's Avatar
riv riv is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Posts: 463 riv User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 37 m 50 sec
Reputation Power: 8
__________________
Words must be weighed, not counted.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreSoftware Design > Sorting a trip from longest or shortest


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 4 hosted by Hostway
Stay green...Green IT