C#排序算法之归并排序

这篇文章主要为大家详细介绍了C#排序算法之归并排序,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了C#实现归并排序具体代码,供大家参考,具体内容如下

代码:

 //归并排序(目标数组,子表的起始位置,子表的终止位置) private static void MergeSortFunction(int[] array, int first, int last) { try { if (first  右子表的数 { temp[tempIndex++] = array[indexB++]; //将右子表的数放入暂存数组中,遍历右子表下标++ } } //有一侧子表遍历完后,跳出循环,将另外一侧子表剩下的数一次放入暂存数组中(有序) while (indexA <= mid) { temp[tempIndex++] = array[indexA++]; } while (indexB <= last) { temp[tempIndex++] = array[indexB++]; } //将暂存数组中有序的数列写入目标数组的制定位置,使进行归并的数组段有序 tempIndex = 0; for (int i = first; i <= last; i++) { array[i] = temp[tempIndex++]; } } catch (Exception ex) { } }


以上就是C#排序算法之归并排序的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » 其他教程