This is most certainly not the recommended way of implementing QuickSort, it assumes there are no duplicates, but it should work:

private IList<int> sort(IList<int> a)
        {
            if (a.Count <= 1)
                return a;
            return sort(a.Where(x => x < a[0]).ToList()).Union(new List<int> { a[0] }).Union(sort(a.Where(x => x > a[0]).ToList())).ToList();
        }

It's a nice demonstration of how C# is getting closer to resemble a proper lambda-oriented functional language.

Tags: computers
Categories: None |

1 comment has been posted.

    Oct. 17, 2011, 12:41 a.m. - Arran Ubels  
    Hah. Nice to know there are other people that do too many things in LINQ one liners. :P
    Reply
Your email: we will send you a confirmation link to this address to confirm your identity and to prevent robot posting
Get in touch
»...«
Follow updates

Join our social networks and RSS feed to keep up to date with latest news and publications