网站大量收购独家精品文档,联系QQ:2885784924

冒泡排序算法(Bubble sort algorithm).doc

  1. 1、本文档共28页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 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

您可能关注的文档

文档评论(0)

jgx3536 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

版权声明书
用户编号:6111134150000003

1亿VIP精品文档

相关文档