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

谁的网站模板利于优化国外搜索引擎网址

谁的网站模板利于优化,国外搜索引擎网址,怎样把自己的网站推广出去,程序员做交友网站排序是指以特定格式排列数据。 排序算法指定按特定顺序排列数据的方式。 最常见的排序是数字或字典顺序。 排序的重要性在于,如果数据是以分类方式存储,数据搜索可以优化到非常高的水平。 排序也用于以更易读的格式表示数据。 下面来看看python中实现的5…

排序是指以特定格式排列数据。 排序算法指定按特定顺序排列数据的方式。 最常见的排序是数字或字典顺序。
排序的重要性在于,如果数据是以分类方式存储,数据搜索可以优化到非常高的水平。 排序也用于以更易读的格式表示数据。 下面来看看python中实现的5种排序方式。

  • 冒泡排序
  • 合并排序
  • 插入排序
  • 希尔排序
  • 选择排序

冒泡排序

它是一种基于比较的算法,其中每对相邻元素进行比较,如果元素不合适,元素将进行交换。

def bubblesort(list):# Swap the elements to arrange in orderfor iter_num in range(len(list)-1,0,-1):for idx in range(iter_num):if list[idx]>list[idx+1]:temp = list[idx]list[idx] = list[idx+1]list[idx+1] = templist = [19,2,31,45,6,11,121,27]
bubblesort(list)
print(list)

执行上面示例代码,得到以下结果 -

[2, 6, 11, 19, 27, 31, 45, 121]

合并排序

合并排序首先将数组分成相等的一半,然后以排序的方式组合它们。参考以下代码实现 -

def merge_sort(unsorted_list):if len(unsorted_list) <= 1:return unsorted_list
# Find the middle point and devide itmiddle = len(unsorted_list) // 2left_list = unsorted_list[:middle]right_list = unsorted_list[middle:]left_list = merge_sort(left_list)right_list = merge_sort(right_list)return list(merge(left_list, right_list))# Merge the sorted halvesdef merge(left_half,right_half):res = []while len(left_half) != 0 and len(right_half) != 0:if left_half[0] < right_half[0]:res.append(left_half[0])left_half.remove(left_half[0])else:res.append(right_half[0])right_half.remove(right_half[0])if len(left_half) == 0:res = res + right_halfelse:res = res + left_halfreturn resunsorted_list = [64, 34, 25, 12, 22, 11, 90]print(merge_sort(unsorted_list))

执行上面示例代码,得到以下结果 -

[11, 12, 22, 25, 34, 64, 90]

插入排序

插入排序包括为排序列表中的给定元素找到正确的位置。 所以在开始时比较前两个元素并通过比较来对它们进行排序。 然后选取第三个元素,并在前两个排序元素中找到它的正确位置。 通过这种方式,逐渐将更多元素添加到已排序的列表中,并将它们置于适当的位置。
参考下面代码的实现 -

def insertion_sort(InputList):for i in range(1, len(InputList)):j = i-1nxt_element = InputList[i]
# Compare the current element with next onewhile (InputList[j] > nxt_element) and (j >= 0):InputList[j+1] = InputList[j]j=j-1InputList[j+1] = nxt_elementlist = [19,2,31,45,30,11,121,27]
insertion_sort(list)
print(list)

执行上面示例代码,得到以下结果 -

[2, 11, 19, 27, 30, 31, 45, 121]

希尔排序

希尔排序涉及排序远离其他的元素。对给定列表的大型子列表进行排序,并继续缩小列表的大小,直到所有元素都被排序。 下面的程序通过将其等于列表大小的一半来找到间隙,然后开始对其中的所有元素进行排序。 然后不断重置差距,直到整个列表被排序。

def shellSort(input_list):gap = len(input_list) / 2while gap > 0:for i in range(gap, len(input_list)):temp = input_list[i]j = i
# Sort the sub list for this gapwhile j >= gap and input_list[j - gap] > temp:input_list[j] = input_list[j - gap]j = j-gapinput_list[j] = temp# Reduce the gap for the next elementgap = gap/2list = [19,2,31,45,30,11,121,27]shellSort(list)
print(list)

执行上面示例代码,得到以下结果 -

[2, 11, 19, 27, 30, 31, 45, 121]

选择排序

在选择排序中,首先查找给定列表中的最小值并将其移至排序列表。 然后为未排序列表中的每个剩余元素重复该过程。 输入排序列表的下一个元素将与现有元素进行比较并放置在正确的位置。 所以最后所有来自未排序列表的元素都被排序。参考以下代码实现 -

def selection_sort(input_list):for idx in range(len(input_list)):min_idx = idxfor j in range( idx +1, len(input_list)):if input_list[min_idx] > input_list[j]:min_idx = j
# Swap the minimum value with the compared valueinput_list[idx], input_list[min_idx] = input_list[min_idx], input_list[idx]l = [19,2,31,45,30,11,121,27]
selection_sort(l)
print(l)

执行上面示例代码,得到以下结果 -

[2, 11, 19, 27, 30, 31, 45, 121]
http://www.hkea.cn/news/508830/

相关文章:

  • 柳州做网站如何建网站详细步骤
  • 黄岛做网站哪家好四川seo关键词工具
  • dede门户网站模版写软文推广
  • 网站开发者排名开发一个app平台大概需要多少钱?
  • 做网站 博客百度推广助手客户端
  • 温州市手机网站制作哪家好爱站网长尾词挖掘
  • 党委网站建设要求凡科建站靠谱吗
  • wordpress 安卓客户端福建seo优化
  • 襄阳seo技术长沙seo网站优化
  • 做一的同志小说网站做seo要投入什么
  • 网站的文件结构百度搜索排名怎么收费
  • 全景网站app网络营销工具分析
  • 南京建设工程交易中心网站seo是什么的简称
  • 利用vps做网站关键字排名查询
  • 常熟网站制作找哪家好品牌型网站制作价格
  • 怎么做自己网站推广网络广告
  • 化州网站建设促销方法100种
  • 长沙专业网站设计平台新闻最新消息10条
  • 惠州网站建设制作宣传推广方案
  • 宁波网站推广外包服务长岭网站优化公司
  • 哈尔滨市哪里做淘宝网站seo课程心得体会
  • 做网站建设公司企业一个企业该如何进行网络营销
  • 移动端h5网站开发服务企业seo推广
  • 管理公司网站建设引擎搜索优化
  • 上市公司专利查询网站百度广告投放价格
  • html5电商网页制作网站怎么seo关键词排名优化推广
  • 大同网站建设黄冈网站推广优化找哪家
  • 昌邑网站建设站长之家网站排名
  • 建设企业网站的需求分析免费域名
  • 重庆欧勒精细有限公司网站策划书百度竞价推广开户