当前位置: 首页 > news >正文

合肥网站建设=388元国外网站做freelancer

合肥网站建设=388元,国外网站做freelancer,如何用子域名做网站,最新合肥封闭小区名单Title of Content 1 冒泡排序 Bubble sort#xff1a;两两交换#xff0c;大的冒到最后概念排序可视化代码实现Python - 基础实现Python - 优化实现Java - 优化实现C - 优化实现C - 优化实现 2 选择排序 Selection sort#xff1a;第i轮遍历时#xff0c;将未排序序列中最小… Title of Content 1 冒泡排序 Bubble sort两两交换大的冒到最后概念排序可视化代码实现Python - 基础实现Python - 优化实现Java - 优化实现C - 优化实现C - 优化实现 2 选择排序 Selection sort第i轮遍历时将未排序序列中最小/大的数放到位置i。概念排序可视化代码实现PythonJava 3 插入排序 Insertion sort每轮将未排序元素插入已排序序列概念排序可视化代码实现PythonJava Merge sortQuick sort 1 冒泡排序 Bubble sort两两交换大的冒到最后 概念 解释 compares adjacent items and swaps them if they are in the wrong order 每轮遍历后的效果 最大/最小的元素到达数字末尾 口诀 对于一个升序序列两两交换大的冒到最后 优化实现 当外层循环对整个数组的一次遍历的这一轮遍历时没有进行交换意味着整个数组已经有序迭代没有必要再进行。 排序可视化 https://www.hackerearth.com/practice/algorithms/sorting/bubble-sort/visualize/ 代码实现 Python - 基础实现 def bubbleSort(intList, sortasc):对整数列表进行冒泡排序。:param intList: 需要排序的整数列表。:param sort: 排序方式asc 表示升序默认desc 表示降序。如果提供了除 asc 或 desc 之外的 sort 参数将默认采用升序排序。:return: None。函数直接对输入的列表进行排序不返回任何值。n len(intList)# 如果 sort 参数不是 asc 或 desc默认为升序if sort not in [asc, desc]:sort ascfor i in range(n):# inner sort# n-i-1 外层每循环i次得到i个最大值在末尾因此这i个位置不用比-1是因为防止j1越界for j in range(n - i - 1):if (sort asc and intList[j] intList[j 1]) or \(sort desc and intList[j] intList[j 1]):temp intList[j 1]intList[j 1] intList[j]intList[j] temp# 测试代码 sample_intList [60, 10, 90, 50, 100, 80, 70, 30, 40, 20] bubbleSort(sample_intList, desc) print(sample_intList) bubbleSort(sample_intList, asc) print(sample_intList)排序结果 Python - 优化实现 增加判断这轮迭代有无进行元素交换的标记swapped def bubbleSort(intList, sortasc):对整数列表进行冒泡排序。:param intList: 需要排序的整数列表。:param sort: 排序方式asc 表示升序默认desc 表示降序。如果提供了除 asc 或 desc 之外的 sort 参数将默认采用升序排序。:return: None。函数直接对输入的列表进行排序不返回任何值。n len(intList)# 如果 sort 参数不是 asc 或 desc默认为升序if sort not in [asc, desc]:sort ascfor i in range(n):# inner sort# n-i-1 外层每循环i次得到i个最大值在末尾因此这i个位置不用比-1是因为防止j1越界for j in range(n - i - 1):swapped False # 这轮循环有无进行交换if (sort asc and intList[j] intList[j 1]) or \(sort desc and intList[j] intList[j 1]):intList[j], intList[j 1] intList[j 1], intList[j]swapped True# 如果刚刚那轮内层的遍历没有进行过交换意味着数组已经有序没有必要再进行后续的遍历if not swapped:breakJava - 优化实现 public class Sort {/*** 对整数数组进行冒泡排序。* * param array 需要排序的整数数组。* param sort 指定排序的类型asc 表示升序desc 表示降序。* 如果提供的 sort 参数不是 asc 或 desc将默认使用升序排序。*/public static void BubbleSort(int [] array, String sort){int n array.length;if (!(sort.equals(asc)||sort.equals(desc))){sortasc;}for(int i0;in;i){boolean swappedfalse;for (int j0;jn-i-1;j){if((sort.equals(asc)array[j]array[j1])||(sort.equals(desc) array[j]array[j1])){swappedtrue;int temparray[j1];array[j1]array[j];array[j]temp;}}if (!swapped){break;}}}public static void main(String[] args) {int[] array{60, 10, 90, 50, 100, 80, 70, 30, 40, 20};BubbleSort(array, asc);for(int i0;iarray.length;i){System.out.printf(%d ,array[i]);}System.out.println();BubbleSort(array, desc);for(int i0;iarray.length;i){System.out.printf(%d ,array[i]);}System.out.println();} }C - 优化实现 C - 优化实现 2 选择排序 Selection sort第i轮遍历时将未排序序列中最小/大的数放到位置i。 概念 解释 At each round i: find the minimum in {item i, item i1, … } and swap it to the position i 每一轮迭代找到一个最小的值将它和这第i轮迭代对应的数组中位置i的原数字位置对调。 每轮遍历后的效果 For each pass, we will move left to right looking for the next largest value. Once that is found, it will be swapped into its final position . 口诀 第i轮遍历时将未排序序列中最小/大的数放到位置i。 初始化时选择数组中第一个值为最大值 排序可视化 https://www.hackerearth.com/practice/algorithms/sorting/selection-sort/visualize/ 代码实现 Python def selectionSort(intList, sortasc):# 升序序列找的是最小值降序序列找的是最大值if not (sort asc or sort desc):sort ascfor i in range(len(intList) - 1):# 每轮循环开始时重置 min_or_max_i 为当前轮的起始位置min_or_max_i i# 每一轮内层迭代的目的是找到带排序序列中最小/大值的下标j并将它赋值给minItem_i记录下来for j in range(i 1, len(intList)):if (sort asc and intList[j] intList[min_or_max_i]) or \(sort desc and intList[j] intList[min_or_max_i]):min_or_max_i j# 找到带排序序列中的最小值后将它赋值给数组的位置i表示他是序列中第i小的元素# 这轮交换后得到的位置i就是它的最终位置因此外层循环只需要遍历len-1遍前len-1个元素有序整体有序if min_or_max_i ! i:intList[i], intList[min_or_max_i] intList[min_or_max_i], intList[i]Java 3 插入排序 Insertion sort每轮将未排序元素插入已排序序列 概念 解释 它的工作原理是通过构建有序序列对于未排序元素在已排序序列中从后向前扫描找到相应位置并插入。 每轮遍历后的效果 At each round i: {item 0, item 1, …, item i} are sorted 得到一个从0-i的有序序列 口诀 每轮将未排序元素插入已排序序列 排序可视化 https://www.hackerearth.com/practice/algorithms/sorting/insertion-sort/visualize/ 代码实现 Python def insertionSort(intList):# 外层循环每一轮迭代i的位置指向的都是本轮未排序的元素for i in range(1, len(intList)):# 内存循环的每一轮迭代从[0,i)是本轮已排序的序列# 目标就是将未排序元素插入已排序序列j iwhile j - 1 0: # 从小到大排序if intList[j] intList[j - 1]:intList[j], intList[j - 1] intList[j - 1], intList[j]j - 1Java Merge sort Quick sort
http://www.huolong8.cn/news/243543/

相关文章:

  • 友点网站建设制作网站数据库
  • ppt做的好的网站安康微信公众平台
  • 好大夫在线网站官网做提眉的医生响水做网站需要多少钱
  • 企业网站建设平台的分析wordpress销售主题
  • 公司网站建设需要哪些内容网站改版 报价
  • 网站开发实现的功能广州网站设计建设
  • 手机站点网站开发技术 主流
  • 惠民县建设局官方网站建设网站申请空间需要多少钱
  • 免费建站系统哪个好用吗石家庄网站建设行业公司
  • html5响应式手机网站学做网站需要多少钱
  • 网页网站建设的ppt模板网站推广运营
  • 兰州企业网站制作网站平台建设保密协议
  • asp.net 网站登陆设计扬州网站建设网站
  • 公司怎么建设网站html手册
  • 网站 名词解释网站建设实验报告总结
  • 建设网站需要的费用济南高端网站制作公司
  • 怎么做一个个人网站珠海网站建设 旭洁科技
  • 酒店官方网站的功能建设四川省建设主管部门网站
  • 成都网站建设推来客熊掌号如何设计网站导航
  • 饰品公司网站建设方案dede视频网站源码
  • wap网站程序福州关键词排名
  • 网站备案到公司名称网站seo的方法
  • ftp 企业网站wordpress 账号密码
  • 阿里云的云服务器做网站用哪种施工企业费用预算的编制的内容包括
  • 口子网站怎么做更好d wordpress
  • 响应式网站 向下兼容电子邀请函免费制作app
  • 杭州网站建设小程序动力论坛源码网站后台地址是什么
  • 泰安 网站建设公司百度优化是什么
  • 新乡网站建设哪家权威wordpress加载本地字体
  • 网站设计费用一览表做外汇的官方网站