visualc++6.0各种排序的算法报告及源程序大学毕设论文

摘要

近几年来,C语言发展迅速,而且成为最受欢迎的语言之一,主要原因是它具有强大的功效,很多著名的系统软件就是由C语言编写出来的。它与汇编语言的结合,更体现出C语言的优越性。

排序算法主要有直接插入排序,折半插入排序,希尔排序,冒泡排序,双向冒泡排序,快速排序,选择排序,堆排序,基数排序这几种。

通过对各种排序方法的比较,我们能够很直观的发现各种排序方法的特点及各自的优缺点。

此次课程设计主要挑选了选择排序、插入排序、冒泡排序这三种排序方法,通过对这三种排序方法的比较,希望能够让大家对一些排序方法有更加直观、深入的了解。 设计中主要解决了用time()、srand()函数辅助rand()函数随机产生了0到99999之间的数据;借助指针申请了动态内存解决了将同一随机数组的三次复制进而确保在相同随机数组的基础上三种比较算法的比较;在各种算法中运用clock()函数计算完成比较所用的时间,并在各种比较算法的编程理解中完成比较、交换次数的计数;将随机数组写入文件等问题。

关键词:随机数 排序 交换 时间

1

目录

1. 设计内容、设计参数及要求·······································1 1.1 设计内容···················································1 1.2 设计参数···················································1 1.3 要求·······················································1 2. 总体设计思路···················································2 2.1 设计系统的功能·············································2 2.2 算法思想···················································2 2.3 系统的总体框架·············································3 2.4 系统的总体流程图···········································4 3. 功能模块的具体设计·············································5 3.1 main( )主函数···············································5 3.2 SelectSort( )函数·············································7 3.3 InsertSort( )函数·············································9 3.4 PopSort( )函数··············································11 3.5 将随机数写入程序··········································13 3.6 welcome( )函数·············································14 4. 模块的调试及测试··············································15 5. 总结与个人体会················································17 5.1 总结······················································17 5.2 个人体会··················································17 6. 致谢··························································19 7. 参考文献······················································20 附程序源代码·····················································21

2

1. 设 计 内 容 和 要 求

1.1 设计内容

⑴通过随机函数随机生成100000个数字,这些数字都是在[0,99999]之间。 (2)并通过设计的排序算法进行排序。这些排序算法中包括冒泡法、选择法、插入法,也可以适当选择其他算法,但必须是较为典型的排序算法。

(3)排序完毕后应给出相应的比较信息,其中包括排序时间,比较次数和交换次数等信息。

(4)在程序的主界面显示出最后的比较结论。 (5)查看完比较结果后,即可点击回车退出系统

1.2 设计参数

(1)将排序前生成的100000个随机数存入一个文本文件中,该文件命名为BeforeSort.txt。

(2)将排序好的数字分别按照不同的排序方式存入不同的文件中,冒泡法排序后的数字存入PopSort.txt中,选择法排序后的数字存入SelectSort.txt中,插入法排序后的数字存入InsertSort.txt中。

1.3 要求

1.3.1 基本要求

精确测试上述三种排序方法对同样的数据进行排序所消耗的时间,比较次数以及交换次数,明确各种排序的编写方法,分析各种排序方法在不同情况下的优劣。

3

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4