Does this seem right? I mean I could show you all the code but this function is kind of self contained. It works so long as all the visuals(a custom type) sent thru it have the same location_z value, but it hangs forever out if they have differant values.

What it does is place the visual into a list, and the list is supposed to be like this when its done:

Static Pointer root->visual(lowest Z value)->...->visual(highest Z value)->Null

and then another function(confirmed working) clears out the list each time.

Everything works pretty much perfectly until you pass it something with a differant Z value, which to me points the finger at this function.

It ends up hanging forever if any Z value is used that is not equal to all other Z values passed.

Code:
void visual::place(visual * new_visual)
{
    // If root is null root points to this visual and it points to null
    if(root == 0)
    {
        root = new_visual;
        new_visual->next_visual=0;
    }
    // Otherwise it will have to be placed in order
    else
    {
        // If root has a higher or same Z
        // Then make visual new root and link it to old root
        if(new_visual->location_z <= root->location_z)
        {
            visual * old_root = root;
            root = new_visual;
            new_visual->next_visual = old_root;                                            
        }
        // Otherwise move down the list and attempt to find
        // a spot where first is <= and second is >= Z
        else
        {
            // Set index to root
            visual * index = root;
            // Control bool
            bool finished = false;
            // Loop until resolved
            while(finished == false)
            {
                // If the next visual is zero we've hit the end and
                // the new_visual is the highest Z
                if(index->next_visual == 0)
                {    
                    // Set the next visual of the index to the new
                    // visual and then set the next visual
                    // of the new visual to null
                    index->next_visual = new_visual;
                    new_visual->next_visual=0;
                    // Declare finished
                    finished=true;
                }
                // Otherwise see if the current index is lower or equal
                // while the next index is greater or equal
                if((index->location_z<=new_visual->location_z) && (index->next_visual->location_z>=new_visual->location_z))
                {
                    // If so, then the new visual next visual becomes the index
                    // next visual
                    // The index next visual then becomes the new visual
                    // This causes an insertion
                    new_visual->next_visual=index->next_visual;
                    index->next_visual = new_visual;
                    // Declare finished
                    finished=true;
                }
                // If not finished, move on to next index and try again
                if(finished==false){index=index->next_visual;}
            }
        }       
    }
}