Jump to content
  • Advertisement
Sign in to follow this  

This topic is 3919 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
The purpose of this is confusing, especially since it involves a stack.

Stack as ADT has two operations, push and pop. Direct manipulation of stack elements doesn't exist at algorithmic level. Even more, your example doesn't even use a stack, since it appears to change object owned indices, not rearange the stack.

If you have a list or array of objects, and this list is strictly ordered, then whenever an object is changed, it needs to be relocated.

This would be essentially a form of partial insertion or bubble sort, given that each time the list changes, the order is fixed so that it strict order is established again.

The efficiency of reordering will depend, but the O complexity can be calculated, realistic efficiency will however depend on "Is Closer". Also, performance of algorithm itself if ran constantly will be similar to that of bubble sort, which isn't known for its speed.

What exactly are you trying to achieve?

Share this post


Link to post
Share on other sites
You're missing something obvious here.

You're keeping a whole list of objects, ordered by distance, while all you really need to know is which one object is the nearest. That list isn't needed at all. No sorting is required. The following (psuedo-code) would do the job just nicely:

closestObject = nothing yet
closestDistance = infinitely high

for each object in list:
if distance to object < closestDistance:
closestObject = object
closestDistance = distance to object

return closestObject

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!