# Old

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

## Recommended Posts

Old [Edited by - Robert Colton on March 1, 2008 9:49:35 AM]

##### Share on other sites
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 on other sites
Old

[Edited by - Robert Colton on March 1, 2008 9:14:57 AM]

##### 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 yetclosestDistance = infinitely highfor each object in list:	if distance to object < closestDistance:		closestObject = object		closestDistance = distance to objectreturn closestObject

##### Share on other sites
Old

[Edited by - Robert Colton on March 1, 2008 9:04:16 AM]

1. 1
Rutin
38
2. 2
3. 3
4. 4
5. 5

• 12
• 10
• 13
• 104
• 11
• ### Forum Statistics

• Total Topics
632983
• Total Posts
3009697
• ### Who's Online (See full list)

There are no registered users currently online

×