CSharp Algorithm - QuickSort

来源:互联网 发布:云计算与应用就业前景 编辑:程序博客网 时间:2024/06/05 15:27

/*

Author: Jiangong SUN

*/

Here I want to explain how to implement "Quick Sort" algorithm in CSharp.

The principle consists of several steps:

1) Get the middle position of an array or list, the list is splitted into two parts

2) Get the first element who is larger than the middle value in the left part, and get the first element who is smaller than middle value in right part, then swap them.

3) Move left variable to right and right variable to left. 

4) Call quick sort method recursively


The implementation of quick sort algorithm.


Call the methods.


The results:



I hope this post will do help to you. Enjoy coding!


reference:

http://snipd.net/quicksort-in-c

http://blog.bossma.cn/csharp/csharp_sort_quicksort/

http://www.kirupa.com/forum/showthread.php?241040-C-QuickSort

http://en.wikipedia.org/wiki/Quicksort

http://www.sorting-algorithms.com/

原创粉丝点击