ok, how does this sound, assuming that u take my advice and create linked lists like i said in above post. here is is:
-list class would need a member that kept track of the number of nodes
-node would need an additional data member, an array of ints representing the distance between itself and the other nodes. the array would need to grow, perhaps a vector would be a better idea? to explain this clearer, lets say there are 3 nodes in list: node 1 would have an array like this, distArray{dist to itself, dist. to node 2, dist. to node 3}, then node 2 array, distArray{dist. to node 1, dist. to itself, dist to node3}, node 3 array distArray{dist. to node1, dist. to node2, dist. to itself}
-the measuring of distances would occur when u insert the node into the list. assuming the node being inserted is not the first node, something like this:
addNode(node *ptr)
{
numNodes++;
node *tmpPtr = head;
node *curPtr = ptr;
int x = 0;
while(tmpPtr->next != NULL&& x<numNodes)
{
val = distance between tmpPtr and curPtr;
tmpPtr[numNodes-1] = val;
curPtr[x] = val;
x++;
tmp = tmp->next;
}
//here u need one more loop for the final node not done(when tmpPtr->next == NULL)
//then set curPtr[x] = 0 as this will represent the distance to itself!
//then attach curPtr to the list
now u have all the distances stored in the arrays. so if there is an odd number of nodes, first thing to do is eliminate the further node, this can be calculated by summing the elements in the array of each node, the largest total is the furthest away and can be eliminated.
- then start with the first node's distance array, find the smallest value in that array(besides 0 of course)
-move to the next node's array. u need to compare 2 things here, 1)to see if u can match the value from the previous step and 2)to make sure that value isnt larger than any values in the current node, as that would mean this node has another node that is closer to it.
-rinse and repeat
-the good thing about this is that u never have to calculate the same distance twice! this was what i was trying to work around.
-however there are still some holes, like how to deal with even distances, how to remove a pair from searching once u have made a match for it, prolly some more things i cant think of. hope that helps a bit. tell me if u come up with something better,this stuff interests me alot!!
:)