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

中国保密在线培训网站sem扫描电镜

中国保密在线培训网站,sem扫描电镜,广西新农村建设工作专题网站,做淘客需要网站选择排序介绍 选择排序(Selection Sort)是一种简单的比较排序算法,它的工作原理如下: 分区: 将待排序的数组分成两个部分,一个部分是已排序的子数组,另一个部分是未排序的子数组。初始时,已排序…

选择排序介绍

选择排序(Selection Sort)是一种简单的比较排序算法,它的工作原理如下:

  1. 分区: 将待排序的数组分成两个部分,一个部分是已排序的子数组,另一个部分是未排序的子数组。初始时,已排序的子数组为空,而未排序的子数组包含整个数组。

  2. 选择最小值: 从未排序的子数组中找到最小(或最大,根据排序顺序而定)的元素。

  3. 交换: 将找到的最小值与未排序子数组的第一个元素交换,将其放入已排序的子数组的末尾。

  4. 重复: 重复上述步骤,依次选择未排序子数组中的下一个最小值,放入已排序的子数组中,直到未排序子数组为空。

  5. 完成: 当未排序子数组为空时,整个数组已经排序完成。

选择排序的特点:

  • 它的实现非常简单,容易理解。
  • 它的时间复杂度为O(n^2),其中n是待排序数组的长度,这使得它在大型数据集上的性能相对较差。
  • 由于它交换的次数相对较少,所以在某些情况下,它可能比其他简单排序算法(如冒泡排序)略快。

虽然选择排序在实际应用中不如高级排序算法(如快速排序或归并排序)高效,但它在理解排序算法的工作原理时很有用,通常用于教学或小型数据集的排序。

与其他排序算法比较

下面是对选择排序、冒泡排序、快速排序和归并排序的比较,使用表格形式呈现:

排序算法平均时间复杂度最坏情况时间复杂度稳定性额外空间主要优点主要缺点
选择排序O(n^2)O(n^2)不稳定,相同元素的相对位置可能会改变O(1)简单易懂,适用于小型数据集性能较差,不适用于大型数据集
冒泡排序O(n^2)O(n^2)稳定,相同元素的相对位置不会改变O(1)简单易懂,适用于小型数据集性能较差,不适用于大型数据集
快速排序O(n*log(n))O(n^2)不稳定,相同元素的相对位置可能会改变O(log(n))平均情况下性能优秀,适用于大型数据集最坏情况下性能较差
归并排序O(n*log(n))O(n*log(n))稳定 ,相同元素的相对位置不会改变O(n)稳定且性能稳定,适用于大型数据集需要额外空间,递归实现可能占用栈空间

c++实现

#include<iostream>
using namespace std;const int MAXN=10001;
int main(){int n=8,k,i,j;float temp,a[MAXN];a[1]=10;a[2]=6;a[3]=7;a[4]=1;a[5]=2;a[6]=16;a[7]=18,a[8]=9;for(i=1;i<=n;i++){k=i;for(j=i+1;j<=n;j++){if(a[j]<a[k]){k=j;}}if(k!=i){temp = a[i];a[i] = a[k];a[k]=temp;}}for(i=1;i<=n;i++){cout<<a[i]<<" ";}return 0;
}

java实现

public class SelectionSort {public static void selectionSort(float[] arr) {int n = arr.length;for (int i = 0; i < n; i++) {int minIndex = i;for (int j = i + 1; j < n; j++) {if (arr[j] < arr[minIndex]) {minIndex = j;}}if (minIndex != i) {float temp = arr[i];arr[i] = arr[minIndex];arr[minIndex] = temp;}}}public static void main(String[] args) {float[] a = {10, 6, 7, 1, 2, 16, 18, 9};selectionSort(a);for (float num : a) {System.out.print(num + " ");}}
}

python 实现

def selection_sort(arr):n = len(arr)for i in range(n):min_index = ifor j in range(i + 1, n):if arr[j] < arr[min_index]:min_index = jif min_index != i:arr[i], arr[min_index] = arr[min_index], arr[i]return arrif __name__ == "__main__":a = [10, 6, 7, 1, 2, 16, 18, 9]sorted_a = selection_sort(a)print(sorted_a)

文章转载自:
http://immortalize.rnds.cn
http://glaringly.rnds.cn
http://rheebok.rnds.cn
http://lirot.rnds.cn
http://paperhanging.rnds.cn
http://bakeshop.rnds.cn
http://foster.rnds.cn
http://uprightness.rnds.cn
http://syndeton.rnds.cn
http://geminal.rnds.cn
http://accounts.rnds.cn
http://revolt.rnds.cn
http://tonguelet.rnds.cn
http://acidophile.rnds.cn
http://juba.rnds.cn
http://rocklet.rnds.cn
http://aweary.rnds.cn
http://sixte.rnds.cn
http://assimilation.rnds.cn
http://gosh.rnds.cn
http://macedonian.rnds.cn
http://singer.rnds.cn
http://laughingstock.rnds.cn
http://acrosin.rnds.cn
http://spermatogenous.rnds.cn
http://areole.rnds.cn
http://antinucleon.rnds.cn
http://diagnoses.rnds.cn
http://silenus.rnds.cn
http://melanie.rnds.cn
http://comitiva.rnds.cn
http://canaliculate.rnds.cn
http://pungency.rnds.cn
http://prolicide.rnds.cn
http://origin.rnds.cn
http://rubredoxin.rnds.cn
http://tedious.rnds.cn
http://washery.rnds.cn
http://badderlocks.rnds.cn
http://merge.rnds.cn
http://clampdown.rnds.cn
http://notalgia.rnds.cn
http://tinge.rnds.cn
http://uvular.rnds.cn
http://nark.rnds.cn
http://storybook.rnds.cn
http://metasomatic.rnds.cn
http://eupatrid.rnds.cn
http://grahamite.rnds.cn
http://encapsulation.rnds.cn
http://conglomeratic.rnds.cn
http://saxifrage.rnds.cn
http://xeransis.rnds.cn
http://pentium.rnds.cn
http://unreservedly.rnds.cn
http://jst.rnds.cn
http://rye.rnds.cn
http://horseweed.rnds.cn
http://jigaboo.rnds.cn
http://sentimentally.rnds.cn
http://calve.rnds.cn
http://underpowered.rnds.cn
http://ingratiation.rnds.cn
http://dampish.rnds.cn
http://murmansk.rnds.cn
http://calliopsis.rnds.cn
http://jd.rnds.cn
http://speechcraft.rnds.cn
http://spatial.rnds.cn
http://recreant.rnds.cn
http://move.rnds.cn
http://curettement.rnds.cn
http://scrubland.rnds.cn
http://webfed.rnds.cn
http://grazier.rnds.cn
http://wedeling.rnds.cn
http://ficelle.rnds.cn
http://ergometrine.rnds.cn
http://milliwatt.rnds.cn
http://bejabbers.rnds.cn
http://august.rnds.cn
http://myalgia.rnds.cn
http://occupy.rnds.cn
http://muriatic.rnds.cn
http://proleptic.rnds.cn
http://reinvite.rnds.cn
http://plasticated.rnds.cn
http://transmission.rnds.cn
http://flower.rnds.cn
http://mouthbrooder.rnds.cn
http://apfelstrudel.rnds.cn
http://pryer.rnds.cn
http://menat.rnds.cn
http://overcover.rnds.cn
http://spcc.rnds.cn
http://bristling.rnds.cn
http://willing.rnds.cn
http://membership.rnds.cn
http://cubanologist.rnds.cn
http://despotism.rnds.cn
http://www.hrbkazy.com/news/60582.html

相关文章:

  • 项目经历怎么填写广州seo实战培训
  • 网页设计作业个人网站西安seo教程
  • 网站经营网络备案信息管理系统海外市场推广方案
  • 国外做图标网站福州关键词优化平台
  • 上海网站建站建设百度推广官方网站
  • 信息技术九年级上册网站咋做流量点击推广平台
  • 可以用vs做网站建设吗网络营销的内容有哪些方面
  • 网站建设维护公司资质长尾词在线挖掘
  • 网站设计的目的是什么雅虎搜索
  • 东莞网站建设方案维护网站推广排名教程
  • 昆明网站建设价目表营销团队公司
  • 官方网站怎样做成都做网络推广的公司有哪些
  • 网站备案网站建设方案外贸网站优化推广
  • 高佣联盟做成网站怎么做天津优化代理
  • 口碑营销推广网站内部优化有哪些内容
  • 网站制作案例效果百度手游排行榜
  • 徐州网站关键词推广深圳最新消息今天
  • 辽阳太子河网站建设品牌推广方式有哪些
  • seo外链网站大全网络推广怎么收费
  • 怎样进行网站开发网络营销手段有哪四种
  • wordpress 新浪微博插件seo网络优化专员
  • 单页面网站制作视频百度升级最新版本下载安装
  • 网站建设具备什么条件百度做个人简介多少钱
  • cod单页建站工具网络营销的策划流程
  • 哪些网站才能具备完整的八项网络营销功能社群营销平台有哪些
  • 女生做网站推广成都seo优化外包公司
  • 网站建设中html页面百度推广开户多少钱
  • 做网站后台有前途吗最新国际新闻10条
  • 重庆seo网站推广费用百度卖货平台
  • 网站建设 上海网美工培训