Java数组排序(冒泡,选择,插入,希尔)



public class SortAll {

/**
* 冒泡排序,选择排序,插入排序,希尔(Shell)排序 Java的实现
* 2008.11.09
* @author YangL. (http://www.idcn.org)
*/
public static void main(String[] args) {
int[] i = { 1, 5, 6, 12, 4, 9, 3, 23, 39, 403, 596, 87 };
System.out.println("----冒泡排序的结果:");
maoPao(i);
System.out.println();
System.out.println("----选择排序的结果:");
xuanZe(i);
System.out.println();
System.out.println("----插入排序的结果:");
chaRu(i);
System.out.println();
System.out.println("----希尔(Shell)排序的结果:");
shell(i);
}

// 冒泡排序
public static void maoPao(int[] x) {
for (int i = 0; i < x.length; i++) {
for (int j = i + 1; j < x.length; j++) {
if (x[i] > x[j]) {
int temp = x[i];
x[i] = x[j];
x[j] = temp;
}
}
}
for (int i : x) {
System.out.print(i + " ");
}
}

// 选择排序
public static void xuanZe(int[] x) {
for (int i = 0; i < x.length; i++) {
int lowerIndex = i;
// 找出最小的一个索引
for (int j = i + 1; j < x.length; j++) {
if (x[j] < x[lowerIndex]) {
lowerIndex = j;
}
}
// 交换
int temp = x[i];
x[i] = x[lowerIndex];
x[lowerIndex] = temp;
}
for (int i : x) {
System.out.print(i + " ");
}
}

// 插入排序
public static void chaRu(int[] x) {
for (int i = 1; i < x.length; i++) {// i从一开始,因为第一个数已经是排好序的啦
for (int j = i; j > 0; j--) {
if (x[j] < x[j - 1]) {
int temp = x[j];
x[j] = x[j - 1];
x[j - 1] = temp;
}
}
}
for (int i : x) {
System.out.print(i + " ");
}
}

// 希尔排序
public static void shell(int[] x) {
// 分组
for (int increment = x.length / 2; increment > 0; increment /= 2) {
// 每个组内排序
for (int i = increment; i < x.length; i++) {
int temp = x[i];
int j = 0;
for (j = i; j >= increment; j -= increment) {
if (temp < x[j - increment]) {
x[j] = x[j - increment];
} else {
break;
}
}
x[j] = temp;
}
}

for (int i : x) {
System.out.print(i + " ");
}
}
}


【HAL库】STM32CubeMX开发----STM32F407----ETH+LAN8720A+LWIP----ping通 本次实验以芯片为MCU,使用25MHz外部时钟源。以太网PHY层芯片为LAN8720A,由MCU引脚PA8提供时钟。 阅读详情

相关推荐

解密电商大促背后的智慧:LSTM与ARIMA模型的双剑合璧

举个例子,如果某东发现某款新推出的电子产品在促销前夕搜索量突然暴涨,虽然这个产品没有过去的销售记录,但LSTM模型可以结合用户对类似产品的行为模式、实时的市场反馈,迅速捕捉到这些变化,并预测这款产品在大促期间的需求会急剧上升。想象一下,如果预测不准确,备货不足,商品很快就卖光了,大量用户可能在促销期间买不到想要的商品,这不仅让用户失望,还会影响某东的品牌形象。这种情况就像我们看一部很长的电视剧,看得越久,前面的情节可能就越来越模糊,到最后有些关键的情节细节都忘了,影响了对整个剧情的理解。

小蒋聊技术 2094

详解Java常用排序算法(10种,含演示动画)

Java常用的排序算法有以下几种: 1. 冒泡排序;2. 选择排序;3. 插入排序;4. 希尔排序;5. 归并排序;6. 快速排序;7. 堆排序;8. 计数排序;9. 桶排序;10. 基数排序。 这些排序算法都有各自的优缺点,应根据具体情况选择适合的算法。

不积跬步无以至千里,不积小流无以成江海。一个喜欢学习分享的程序员 3万+

迈创cameralink采集卡安装操作说明

迈创cameralink采集卡安装操作说明MIL软件安装MIL软件下载获取MIL软件安装MIL软件安装常见问题 MIL软件安装 MIL软件下载获取 MIL软件安装 解压MIL安装包,点击MilSetup.exe开始安装,如下图所示; 备注:64位系统MIL软件可以同时安装32位和64位客户端,本文档默认安装64位客户端,64位系统安装32位MIL方法后续再展开讲(不建议这样用,很麻烦) 点击Launch Installation开始安装,64位系统,默认只安装64位MIL客户端 根据采集卡驱动,选择M

qq_23107577的博客 9381

排序算法总结及java实现

十种排序算法的基本特性: 排序算法 平均时间复杂度 最好情况 最坏情况 空间复杂度 排序方式 稳定性 快速排序 Ο(nlogn) Ο(nlogn) Ο(n2) Ο(logn) in-place 不稳定 归并排序 Ο(nlogn) Ο(nlogn) Ο(nlogn) Ο(n) out-place 稳定 堆排序 Ο(nlogn) Ο(nlogn) Ο(nlogn) Ο(1) i...

谬也的博客 545

COMSOL新手必看:手把手教你搭建锂电池P2D模型(附完整参数设置)

本文为COMSOL新手提供了搭建锂电池P2D仿真模型的详细指南。文章从模型原理入手,逐步讲解软件设置、几何构建、关键参数配置及后处理分析,并探讨了如何将仿真结果与智能电池管理中的SOC、SOH估算相结合,为电池性能分析和BMS算法开发提供实用洞见。

transformer2023的博客 238

散户逆袭神器:用通达信DIY指数发现下一个光伏储能(附龙头股筛选模板)

本文详细介绍了如何利用通达信软件的自定义指数功能,构建个人专属的行业监控工具,以发现类似光伏储能这样的潜力赛道。文章提供了从零开始的指数编制步骤、核心的龙头股筛选模板,以及五个关键的数据校验技巧,帮助散户投资者实现机构级的行业分析与机会挖掘,有效提升投资决策能力。

w3x4y的博客 487

【JAVA】常见的七大排序

本篇主要介绍常见的七大排序,实现语言为Java,其主要分为:直接插入排序,希尔排序,直接选择排序,堆排序,冒泡排序,快速排序,归并排序。在介绍七大排序之前我们先来认识一下排序的概念。

qq_63218110的博客 2936

欧姆龙PMAC CK3M控制器新手避坑指南:从开箱到EtherCAT总线配置的完整流程

本文详细介绍了欧姆龙PMAC CK3M控制器的完整配置流程,从开箱检查到EtherCAT总线配置,特别针对新手常见问题提供避坑指南。内容包括硬件连接、软件安装、EtherCAT主站初始化、从站配置、电机参数设置等关键步骤,帮助工程师快速掌握PMAC控制器的使用技巧。

weixin_42532938的博客 395

8大Java排序方法(由简入繁),有代码详解和原理指导

Java8大排序方法

Byyyi耀的博客 4740

百度地图小区边界爬取

百度地图 小区边界爬取 完整项目地址-github 数据源:百度地图api 项目结构 RESIDENTIALAREABOUNDARY │ ResidentialAreaBoundaryControl.py 主函数 │ ResidentialAreaBoundaryFunc.py 方法库 │ ├─Auxiliary │ crawelFunc.p...

fulin9452的博客 6406

高速设计注意事项总结——MDI篇

在以太网高速通信系统中,MDI(Medium Dependent Interface,介质相关接口)是连接物理层芯片(PHY)与传输介质(如网线)的关键接口,其设计直接影响信号完整性、传输速率和抗干扰能力。本文围绕 MDI 及 RJ45 接口电路、关键参数、设计与布线要点展开,为高速以太网设计提供参考。本文包含MDI 及 RJ45 接口电路组成、电路设计注意事项、布局布线要求等内容

qq_16237389的博客 1465

java7种排序(需熟练掌握)

java7种排序算法 文章目录java7种排序算法@[toc]1.冒泡排序2.插入排序3.选择排序4.希尔排序5.归并排序6.快速排序7.基数排序(基于桶排序) 1.冒泡排序 public void bubbleSort(int[] array){ for (int i = 0; i < array.length-1; i++) { boolean flag=false; for (int j = 0; j <array.lengt

qq_53280986的博客 3639

OCTA-500:用于光学相干断层扫描血管造影研究的视网膜数据集|文献速递-基于生成模型的数据增强与疾病监测应用

数据集提供了丰富的图像和注释,包括两种模态(OCT/OCTA体积)、六种投影类型、四种文本标签(年龄/性别/眼别/疾病)以及七种分割标签(大血管/毛细血管/动脉/静脉/2D FAZ/3D FAZ/视网膜层)。我们介绍了新的 OCTA-500 数据集,该数据集包含来自 500 名受试者的 OCTA 成像,并提供了丰富的图像和标注集。(C) OCTA-500 切片的人工标注示例。图 4. OCTA-500 数据集中文本标签的统计直方图:(a) 性别,(b) 眼别,(c) 年龄,(d) 疾病。

weixin_38594676的博客 1445

Java数组排序总结(冒泡,选择,插入,希尔)

public class SortAll { /** * 冒泡排序,选择排序,插入排序,希尔(Shell)排序 Java的实现 2008.11.09 * * @author YangL. (http://www.idcn.org) */ pu

我思故我在 901

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

java类实现数组的五种排序 冒泡排序、选择排序、插入排序、希尔排序、数组排序

public class sort { /** * @param args * 对数组进行排序冒泡排序、选择排序、插入排序、希尔排序、数组排序 * 五种排序的方法 */ public static void main(String[] args) { // TODO Auto-generated method stub int a[] = new int[7]; a[0]=12; a

何足道也 816

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

java数组排序算法01-冒泡,选择,希尔排序,插入排序

java数组排序算法 冒泡排序 原理:数组元素两两比较,交换位置,大元素往后放,经过一轮比较后,最大的元素,就会出现在最大索引处。 O(n^2) public class BubbleSort { public static void main(String[] args) { int[] arr = {1,34,23,3,45,6}; int[] arr2 = bubble(arr); for (int i = 0; i < arr2.leng

shake_shark_pp 163

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

Java数组排序总结(冒泡,选择,插入,希尔)

package org.idcn.jse;    public class SortAll {     /**   * 冒泡排序,选择排序,插入排序,希尔(Shell)排序 Java的实现    * 2008.11.09   * @author YangL. (http://www.idcn.org)   */   public static void main(String[] args) {

liujinwei2005的专栏 703

java 数组 起泡排序_Java数组排序(冒泡,选择,插入,希尔)

public class SortAll {/*** 冒泡排序,选择排序,插入排序,希尔(Shell)排序 Java的实现* 2008.11.09* @author YangL. (http://www.idcn.org)*/public static void main(String[] args) {int[] i = { 1, 5, 6, 12, 4, 9, 3, 23, 39, 403, ...

weixin_33511258的博客 78

Java数组排序总结(冒泡,选择,插入,希尔)

public class SortAll {      /**    * 冒泡排序,选择排序,插入排序,希尔(Shell)排序 Java的实现     * 2008.11.09    * @author YangL. (http://www.idcn.org)    */   public static void main(String[] args) {     int[] i = { 1, 5

ihc523的专栏 540

Java实现数组排序总结篇(冒泡,选择,插入,希尔)

package org.liuxin.interview; /** * * @author LiuBeY(http://liubey.iteye.com) */ public class SortAll { public static void main(String[] args) { int[] i = { 1, 5, 6, 12, 4, 9...

Liubey的只言片语 137
上一篇: 输出一个数字序列str(字符串)中相邻数字之和为n的数字
下一篇: PHP获得本周日期
JavaNoob
博客等级 码龄19年 4粉丝 100原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址