Quicksort causes stackoverflow...

Posted by Tony on Stack Overflow See other posts from Stack Overflow or by Tony
Published on 2010-01-19T12:42:31Z Indexed on 2010/05/11 21:14 UTC
Read the original article Hit count: 334

I have the following code, (taken from here), but it causes a stackoverflow exception when there's two the same value's in the list to sort.

Can someone help me what's causing this?

 public static IEnumerable<int> QSLinq(IEnumerable<int> _items)
{
    if (_items.Count() <= 1)
        return _items;

    var _pivot = _items.First();

    var _less = from _item in _items where _item < _pivot select _item;
    var _same = from _item in _items where _item == _pivot select _item;
    var _greater = from _item in _items where _item > _pivot select _item;

    return QSLinq(_less).Concat(QSLinq(_same)).Concat(QSLinq(_greater));
}

© Stack Overflow or respective owner

Related posts about quicksort

Related posts about stackoverflowexception