Q:

StackOverflowException when perform Quicksort with ordered list

I'm implementing Quick sort algorithm in C#.  Implementation as follow:
    /// <summary>
    /// Perform Sort
    /// </summary>
    /// <returns></returns>
    public override List<int> Sort(List<int> list)
    {
        try
        {
            this.quick(ref list, 0, list. Count - 1);

            return list;
        }
        catch (Exception)
        {                
            throw;
        }
    }

    /// <summary>
    /// Quick sort main algorithm
    /// </summary>
    /// <param name="list"></param>
    /// <param name="left"></param>
    /// <param name="right"></param>
    private void quick(ref List<int> list, int left, int right)
    {
        try
        {
            int i, j;
            int x, y;
            i = left;
            j = right;
            x = list[left];

            do
            {
                while (list[i] < x && i < right)
                {
                    i++;
                }

                while (list[j] > x && j > left)
                {
                    j--;
                }

                if (i <= j)
                {
                    y = list[i];
                    list[i] = list[j];
                    list[j] = y;

                    i++;
                    j--;
                }
            }
            while (i <= j);

            if (left < j)
            {
                this.quick(ref list, left, j);
            }

            if (i < right)
            {
                this.quick(ref list, i, right);
            }
        }
        catch (Exception)
        {                
            throw;
        }
    }

If I call Sort and pass in an unordered list, it works ok.  But if I pass in an ordered list, a StackOverflowException occur.  I tried to figure out why is it but still have no clue.  So please point out for me what wrong did I do. 
Update
I found the cause of error: at the first recursion, the algorithm set j = -1, so that i will never meet j, and led to StackOverflow.  So how to get rid of this behavior?  I mean is there anyway to figure out that the list that has been passed in is an ordered list and terminate the algorithm? 

A:

Without inspecting your code...
The naive quicksort has best-case complexity of O(n log n), but worst case of only O(n).  The worst case is (you guessed it) when the list is sorted.  On a sorted collection, the pivot chosen as the leftmost element will separate a sublist into an empty list and everything else, and then recurse into a sublist that is just one element less than the original (the pivot).  Thus, your stack depth needs to be at least the same as the number of elements you're sorting.  So if you have a largish collection, a StackOverflowException is not unexpected. 
The only fix, really, is not using the naive quicksort.  You can detect if the collection is sorted or nearly sorted and switch to another algorithm; or you can use another method of choosing a median that will decrease the likelihood of the degenerate case (for example, while sorted collections are commonly possible, such collections that will trigger a degenerate case when you select the middle element instead of the left one as pivot are much rarer).  Cases where you expect near-sorted collections to be common can also benefit from three-value-median method of pivot selection; many more variations are possible. 
EDIT: If you have a bug in your code, that is a pretty good source of errors too :P An empty list is sorted by default - nothing to do, move along... Same with one-element lists.  So if you just have a check if right is before or at left and return early without changing it, your bug should go away.  It's as simple as
if (right < left) return;

