CSharp Algorithm - QuickSort

本文详细介绍了如何在C#中实现快速排序算法,并通过具体步骤解析其工作原理。包括选取中间位置元素作为基准,对数组进行划分等关键操作。

/*

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/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值