排序算法 - int - C的向量 [英] Sorting algorithm - vector of int - C

查看:70
本文介绍了排序算法 - int - C的向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

晚上好



我有一个int向量,我需要按升序进行排序,我正在寻找最优化的算法做到这一点。

对于我的情况,我猜 quicksort 是最推荐的一个,但无论如何我想检查一下是否正确。



我有6个案例需要测试:

*随机生成10个百万元素数组

*随机生成100个百万元素数组

* 10万元素数组已经排序

* 100万元素数组已经排序

* 10万元素数组按降序排序

* 100个百万元素数组按降序排序



我看到人们建议使用某些算法,直到达到某个点e然后使用另一个来改进优化。

对于我的情况,我应该根据数组大小更改算法,还是没有必要?有没有其他方法可以改善这些测试?

Good Evening

I have a vector of int that I need to sort in ascending order and I am looking for the most optimized algorithm to do it.
For my case I guess quicksort is the most recommended one, but anyway I would like to check if that's right.

I have 6 cases that I want to test:
* 10 milion elements array generated randomly
* 100 milion elements array generated randomly
* 10 milion elements array already sorted
* 100 milion elements array already sorted
* 10 milion elements array sorted in descending order
* 100 milion elements array sorted in descending order

I saw people recommending to use some algorithm until I reach certain point e then use another for improving optimization.
For my case should I change the algorithm depending on the array size or it isn't necessary? Is there any other way that can improve those tests?

推荐答案

看起来像家里的工作。



为什么不在你的代码中添加时间度量,实现不同的算法并测量不同情况的结果。

这应该给你答案哪种方法对每种情况最有效(或者对所有情况而言) 。
Looks like home work to me.

Why not add time measure to your code, implement different algorithms and measure the outcome for the different cases.
That should give you the answer which method is most efficient for each case (or maybe for all).


如果只有CodeProject有之一有关该主题的最佳文章 [ ^ ]。
If only CodeProject had one of the best articles on the subject[^].


你知道主要的排序算法已经被研究过并且它们的性能是已知的(我会推荐 oldie-goldie Wirth的书 [ ^ ]作为起点)。



如果你真的很想测量你的套装的性能然后没有人阻止你这样做。
You know the major sorting algorithms have been studied and their performance is known (I would reccomend the oldie-goldie Wirth's book[^] as starting point).

If you are really curious to measure the performance on your set of data then no one prevents you in doing that.


这篇关于排序算法 - int - C的向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆