Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# Insertion Sort Help for a Green Horn

Greenhorn
Posts: 16
Hello,
I have an array that contains Points that are found on an X-Y axes. I am trying to sort these Points by their closeness to one another. In theory, I need to take the first point in my array, add it to the new array. Then take the second point in my array and insert it into the second place in the new array..heres where the fun starts...I then take the third point of my first array and check to see how far it is from the each of the 2 points in my new array, then it gets inserted into the new array directly after the point to which it is closest. Then we go to the fourth point and compare its distance from each of the 3 points in my new sorted array and insert it after the point that it is closest and so on until I run out of points...I am completely lost on this one...I am not looking for someone to feed me a ton of code that I can just plug in and go, I would like for someone to just point me in the right direction so I can at least get started...
Jason

Ranch Hand
Posts: 154
You could have 20 different points each of which is an equal distance from at least one other point.
Are you sure the question isn't their proximity to 1 given point?

Greenhorn
Posts: 26
Hi,
Here's some pseudocode I've come up with, hope it's correct..

When inserting into the array, you'll have to shift all elements after the insertion point by one step to the right. You could use vector instead of array to make insertion easier.
I'm assuming that the minimum distance between points will always be less than 999999 (or some such similiar huge number).
If the new point is equally "least distant" from several other points, it will be placed right after the first such point.

Ravi
[ March 12, 2004: Message edited by: Ravi Srinivas ]
[ March 12, 2004: Message edited by: Ravi Srinivas ]

jason candelora
Greenhorn
Posts: 16
Thanks for all of the help!! I will sooon have this one completed!

 I've got no option but to sell you all for scientific experiments. Or a tiny ad: The WEB SERVICES and JAX-RS Course https://coderanch.com/t/690789/WEB-SERVICES-JAX-RS