不改变数据位置的排序算法及动态演示
宁 宁1,张 霞2
(1.潍坊教育学院信息工程系,山东 青州 262500;
2.潍坊教育学院数学系,山东 青州 262500)
摘要:实际应用中经常遇到要求不改变原始数据的顺序而按关键字的大小对数据进行排序的情况,原有的一些经典排序算法不能直接用于解决该类问题。经过对选择排序算法进行研究,给出了基于选择思想的不改变数据位置而对数据进行排序的算法,并利用C#语言编程对该算法的实现过程进行了动态演示。
关键词:排序 ; 关键字 ; 选择 ; 定时器
Sorting Algorithm Without Changing the Data Position & Dynamic Demonstration
1.FU Ning 2.ZHANG Dong-xia
(1.The Information Engineering Department of Weifang College of Education,Qingzhou Shandong 262500)(2.The Information Engineering Department of Weifang College of Education,Qingzhou Shandong 262500)
Abstract:In practical application, the situation, in which it requires a listing of the data in the order of the size of the keywords without changing the order of the original data, is an often-met case. The original classic sorting algorithm cannot be used directed to solve this kind of problem. This paper, by researching into the selective sorting algorithm, puts forward an algorithm on the basis of sorting the data without changing the positions of the data. It also gives a dynamic demonstration of the realization procedure of this algorithm by applying the C language programming.
Keywords:sorting ; key word ; select ; timer
1. 问题的提出
排序是计算机程序设计中一项基本的操作,在实际应用中,有很多情况下需要对数据按照某种方式进行排序后才能达到某种要求,因此,学习和研究各种排序方法是计算机工作者的重要课题之一。
我们已经熟知的、比较成熟的排序算法有很多,比如冒泡排序、选择排序、插入排序、快速排序等,利用这些排序算法都能够使一组数据序列按照某个关键字排成需要的顺序。但这些经典的排序算法在对数据序列排序时,都要改变数据的原始顺序,也就是说,在一般情况下,排序问题的输入是n个数a1,a2,a3,……,an的一个序列,按照某个关键字对初始序列进行重新排序后产生初始输入序列的一个重新排列:a11, a21, a31, ……,an1,使得a11< a21< a31
待排序数据:( 596 560 480 616 560 580 498 500 540 610)
对应的名次:( 3 5 10 1 o 5 4 9 8 7 2 )
对于实际工作中类似的排序要求,原有的一些基础排序算法就不能够直接应用,在具体的编程应用中可以在一些经典排序方法的基础上适当做一些改进,来解决具体的问题。本文基于选择排序算法的基本思想,给出了对不改变数据位置而对数据进行排序的有效算法,并利用C#语言编程给出了该算法实现的动态演示。
2. 算法实现
假设要处理的数据存放在A数组中,为了我们算法实