Dynamic Array print function
<p>In this post</p>

<p><a href="http://codereview.stackexchange.com/questions/5745/dynamic-array-improvements-0">http://codereview.stackexchange.com/questions/5745/dynamic-array-improvements-0</a></p>

<p>What does this mean?  Sorry if the question is vague..I just need to update my print_array function.  Full code is below..for my poor man's dynamic array.  </p>

<p>Can someone tell me how the overloaed &lt;&lt; function works?</p>

<pre><code>// My Current Print Array
void print_array() 
{ 
    for (int i = 0; i &lt; size; i++) cout &lt;&lt; array[i] &lt;&lt; endl; 
} 
</code></pre>

<p>If you are going to write print_array at least write it so that it can use alternative 
stream (not just std::cout). Then write the output operator.</p>

<p>// SO user advice</p>

<pre><code>std::ostream&amp; operator&lt;&lt;(std::ostream&amp; stream, dynamic_array const&amp; data)
{
    data.print_array(stream); // After you fix print_array
    return stream;
}    
</code></pre>

<p>// My Dynamic Array Class</p>

<pre><code>#include "c_arclib.cpp"
template &lt;class T&gt; class dynamic_array
{
private:
    T* array;
    T* scratch;
public:
    int size;

    dynamic_array(int sizein)
    {  
        size=sizein;
        array = new T[size]();
    }

    void print_array()
    {  
        for (int i = 0; i &lt; size; i++) cout &lt;&lt; array[i] &lt;&lt; endl;
    }

    void merge_recurse(int left, int right)
    {  
        if(right == left + 1)
        {  
            return;
        }
        else
        {  
            int i = 0;
            int length = right - left;
            int midpoint_distance = length/2;
            int l = left, r = left + midpoint_distance;
            merge_recurse(left, left + midpoint_distance);
            merge_recurse(left + midpoint_distance, right);
            for(i = 0; i &lt; length; i++)
            {  
                if((l &lt; (left + midpoint_distance)) &amp;&amp; (r == right || array[l] &gt; array[r]))
                {  
                    scratch[i] = array[l];
                    l++;
                }
                else
                {  
                    scratch[i] = array[r];
                    r++;
                }
            }
            for(i = left; i &lt; right; i++)
            {  
                array[i] = scratch[i - left];
            }
        }
    }

    int merge_sort()
    {  
        scratch = new T[size]();
        if(scratch != NULL)
        {  
            merge_recurse(0, size);
            return 1;
        }
        else
        {  
            return 0;
            }
    }

    void quick_recurse(int left, int right)
    {  
        int l = left, r = right, tmp;
        int pivot = array[(left + right) / 2];
        while (l &lt;= r)
        {  
            while (array[l] &lt; pivot)l++;
            while (array[r] &gt; pivot)r--;
            if (l &lt;= r)
            {  
                tmp = array[l];
                array[l] = array[r];
                array[r] = tmp;
                l++;
                r--;
            }
        }
        if (left &lt; r)quick_recurse(left, r);
        if (l &lt; right)quick_recurse(l, right);
    }

    void quick_sort()
    {  
        quick_recurse(0,size);
    }

    void rand_to_array()
    {  
        srand(time(NULL));
        int* k;
        for (k = array; k != array + size; ++k)
        {  
            *k=rand();
        }
    }
};

int main()
{  
    dynamic_array&lt;int&gt; d1(10);
    cout &lt;&lt; d1.size;
    d1.print_array();
    d1.rand_to_array();
    d1.print_array();
    d1.merge_sort();
    d1.print_array();
}
</code></pre>

<p>~
~</p>
