- 1、本文档共28页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
冒泡排序算法(Bubble sort algorithm)
冒泡排序算法(Bubble sort algorithm)
Collected by oneself
Mistakes are unavoidable
For reference only
In case of error
Please correct me! Thank you
Bubble sort algorithm
Before explaining the bubble sort algorithm
Lets first introduce an algorithm that puts the largest number of 10 numbers (placed in an array A) in the last position
The algorithm is described below:
(1) from array A[1] to A[10]
The two adjacent numbers are compared
That is, A[1] and A[2] compare
After comparison, A[2] compares with A[3]
... finally, A[9] and A[10] compare
(2) in the course of each comparison
If the previous number is larger than the latter one
Then you change two numbers
That is, move the larger number to the back
Smaller to the front
For example, in the first comparison
If A[1] is larger than A[2], the values of A[1] and A[2] are interchanged
The following figure uses 6 data to illustrate the above algorithms
Suppose the 6 data is: A[]=5 74386
A[1], A[2], A[3], A[4], A[5], A[6]
574386 first time
Comparison of A[1]=5 and A[2]=7
75
No swap
574386, second times
Comparison of A[2]=7 and A[3]=4
47
Swap
Then, after the second comparison, the data is 547386
547386, third times
Comparison of A[3]=7 and A[4]=3
37
Swap
Then, after the third comparison, the data is 543786
543786, Fourth Times
Comparison of A[4]=7 and A[5]=8
87, no swap
543786, fifth times
Comparison of A[6]=6 and A[5]=8
68
Swap
Then the fifth and last result is...
543768
As can be seen from the above example
For 6 numbers
A row (maximum number) requires 5 Comparisons
It can be deduced that...
For the number of N
One trip requires N-1 times to compare operations
The above algorithm has put the largest number of N numbers into the A[N]
Repeat the above algorithm
Put the maximum number of A[1] to A[N-1] in A[N-1]
In this way, second large numbers are stored in A[N-1]
Next, put the maximum number of A[1] to A[N-2] in A[N-2]
... finally, put the big A[1] to A[2] in the A[2]
After each repetition, 22 after comparison
Compare the range and
您可能关注的文档
- 体育课游戏大全(Sports lessons).doc
- 何谓快门速度的安全限度(What is the shutter speed limit).doc
- 余世维-成功经理人有感(Yu Shiwei - a sense of successful managers).doc
- 余世维 经典ppt7(Yu Shiwei classics ppt7).doc
- 作业范例(Operation example).doc
- 作为发展中国家中国如何发展低碳经济(As a developing country, how can China develop a low carbon economy).doc
- 作为社会论坛的戏剧(Drama as a Social Forum).doc
- 作品_猜数字游戏实训代码(Work _ guessing game training code).doc
- 作文万能句(Composition sentence).doc
- 作文万能开头结尾(Composition always begins at the end).doc
- 冒险岛单机gm命令孙光推荐(Adventure Island single GM command sun recommended).doc
- 写作绝招((Writing skill).doc
- 农业基础知识(Basic knowledge of Agriculture).doc
- 写字教案(Writing lesson plan).doc
- 写给即将毕业的电子信息工程专业的女生(For a graduate student of Electronic Information Engineering).doc
- 农夫打发(The farmer sent away).doc
- 农村中学心理健康教育模式初探(A probe into the mental health education model in rural middle schools).doc
- 农村义务教育学生营养改善计划管理制度(Rural compulsory education students, nutrition improvement plan, management system).doc
- 农村信用社招聘银行会计复习试题(Rural credit cooperatives recruitment bank accounting review questions).doc
- 农村信用社顾客服务管理(Rural credit cooperatives, customer service, management).doc
文档评论(0)