public static void main(String[] args) {
LinkedList<Integer> linkedList = new LinkedList<Integer>();
linkedList.add(1);
linkedList.add(6);
linkedList.add(2);
linkedList.add(3);
linkedList.add(8);
linkedList.add(2);
linkedList.add(12);
LinkedList<Integer> list = sort(linkedList);
for(int i = 0; i < list.size() ; i++){
System.out.println(list.get(i));
}
}
public static LinkedList sort(LinkedList<Integer> linkedList){
int low , high , mid , num;
int intmid=0 , inthigh=0 , intlow =0;
for(int i =1 ; i < linkedList.size() ; i ++){
low = 0 ; high = i-1; mid = high/2; num = linkedList.get(i);
//折半查找插入位置
while(low <= high){
intmid = (int) linkedList.get(mid);
if(num <= intmid){
high = mid - 1;
mid = (low+high)/2;
}else{
low = mid+1;
mid = (low+high)/2;
}
}
num = linkedList.get(i);
linkedList.remove(i);
linkedList.add(high+1 , num);
}
return linkedList;
}
相关推荐
Carsim和Matlab/Simulink联合仿真时Carsim匹配不到Matlab的解决方法
本人使用Carsim和Matlab/Simulink联合仿真做过用机器学习方法解决ACC和简单换道的仿真,曾将8.02 2016 2018三个版本Carsim反复安装N次,有相同方向的同学或安装过程遇到问题的同学可以加本人qq505625869一起交流经验心得。 一.前言 Carsim是一款很好的联合仿真软件,使用Carsim,可以避免搭建很多非常复杂的动力学模型
排序算法2——折半插入排序
编写折半插入排序算法,对元素序列 75、61、82、36、99、26、41进行从小到大排序。 【算法思想】 折半插入排序算法是对直接插入排序的一种改进。主要思想是在查找插入位置过程中引入折半查找算法思想,利用折半查找法在有序集中确定待排序元素插入位置。 【与直接插入排序的区别】 *直接插入排序:从右到左按照顺序查找插入的位置。 *折半插入排序:在有序集中查找插入的位置。 【示例】 假设有...
基于springboot医院医疗仪器管理系统
基于Spring Boot的医院医疗仪器管理系统是一款专门为医院设计的高效管理工具。
数据结构与算法基础(王卓)(33):折半插入排序、希尔排序
目录折半插入排序 Project 1:问题:缺少在插入元素之前的移动元素的操作Project 2:(最终成品、结果)希尔排序 Project 1:(个人思路)标准答案:(PPT答案)解释说明:(在程序实际执行的时候的算法运行逻辑顺序实际上和王卓老师网课中所讲的有所不同)(1):赋值阶段(2):第一轮【第一次】比较 (3):第二轮到第(d)轮【第一次】比较(4):第一轮到第(d)轮【第2次及其后续的】比较重点来了:至于如何调整先后进行比较时,不同的间隔大小d的问题,这里标准答案给出的方法是:王道答案:本土化直
【已解决】如何在服务器中下载huggingface模型,解决huggingface无法连接
在服务器上使用huggingface模型时,如果直接指定模型名称,用AutoTokenizer.from_pretrained(“model_name”),可能会由于网络原因会报错 Failed to connect to huggingface.co port 443 after 75018 ms: Operation time out因此我们需要下载模型到服务器上,得到模型本地的路径model_dir,再通过AutoTokenizer.from_pretrained(model_dir)方式来使用。
Maya绑定:人物绑定详细案例(创建骨骼、镜像骨骼、IK创建、IK打组、IK控制器、FK控制器、烘焙动画、导出)
Maya绑定:人物绑定详细案例(创建骨骼、镜像骨骼、IK创建、IK打组、IK控制器、FK控制器、烘焙动画、导出)
数据结构作业3-4(周)问题 C: 算法10-2——折半插入排序
题目描述 折半插入排序同样是一种非常简单的排序方法 它的基本操作是在一个已经排好序的有序表中进行查找和插入。 不难发现这个查找的过程可以十分自然的修改成折半查找的方式进行实现。 折半插入排序的算法可以描述如下: 在本题中,读入一串整数,将其使用以上描述的折半插入排序的方法从小到大排序,并输出。 输入 输入的第一行包含1个正整数n,表示共有n个整数需要参与排序。其中n不超过1000。 第二行包含n个用空格隔开的正整数,表示n个需要排序的整数。 输出 只有1行,包含n个整数,表示从小到大排序完毕的所有整数
多目标进化算法——NSGA-II(python实现)
NSGA-II(python实现)--最全注释,痴呆能懂--
【经典算法5——折半插入排序】
排序是计算机内经常进行的一种操作,其目的是将一组“无序”的记录序列调整为“有序”的记录序列。例如:将下列关键字序列调整为。
本地玩转AI还得靠这个,SillyTavern(酒馆)到底有多强?
SillyTavern是一款本地运行的LLM交互前端,支持文本生成、图像生成、语音合成等功能。它最初是TavernAI的分支,现已独立开发,社区活跃,功能更新频繁。SillyTavern通过前端UI和插件系统连接各种大模型后端,如OpenAI、KoboldAI等,用户可以在本地创建“虚拟酒馆”与各种角色对话。其功能亮点包括角色卡、角色记忆、世界设定、多人聊天室、自定义UI和行为脚本、插件扩展支持等。SillyTavern适合AI创作用户、AI工程师、LLM爱好者和AIGC创作者。它有两个维护分支:relea
基于风机和水轮机互补发电系统的Simulink仿真
随着全球对清洁能源的需求不断增长,风力发电和水力发电作为两种重要的可再生能源发电方式,受到了广泛关注。风机和水轮机互补发电系统结合了两者的优势,能够在不同的自然条件下稳定地输出电能,提高能源利用效率和供电可靠性。本文将详细介绍风机和水轮机互补发电的原理,包括风力发电原理、水力发电原理以及两者互补的机制和优势,并通过相关数学公式进行深入分析。水轮机也有其特定的特性曲线,包括流量 - 水头曲线、功率 - 流量曲线等。在不同的水头和流量条件下,水轮机的输出功率会发生变化。
折半插入排序
介绍折半插入排序
扰动观察法MPPT控制器simulink仿真
最大功率点跟踪(MPPT)控制器对于光伏(PV)系统至关重要,因为它可以确保系统在所有操作条件下都能从光伏阵列中提取最大功率。扰动观察法(P&O)是一种广泛使用的MPPT算法,因为它简单且易于实现。本文介绍了P&O MPPT控制器的Simulink仿真,并分析了其性能。
2024年网络安全最全5分钟了解折半插入排序(2),作为字节跳动面试官
第二次比较,从无序表中取出第一个数 6,与中间值1比较,6>1,要放在1的后面,再与后半区(有序表:2)的中间值2比较,6>2,6插入到2的后面,得到。第三次比较,从无序表中取出第一个数 7,与中间值2比较,7>2,7放在2后面,再与后半区(有序表:6)的中间值6比较,7>6,7放在6后面,得到。第一次比较,从无序表中取出第一个数 1,与中间值2比较,1
老版QQ原生表情gif动态
这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。
深度学习工具包 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');```[](https://bitdeli.com/free "Bitdeli Badge")
2024年最新5分钟了解折半插入排序,2024最新百度、头条等公司网络安全社招面试题目
当我学到一定基础,有自己的理解能力的时候,会去阅读一些前辈整理的书籍或者手写的笔记资料,这些笔记详细记载了他们对一些技术点的理解,这些理解是比较独到,可以学到不一样的思路。第二次比较,从无序表中取出第一个数 6,与中间值1比较,6>1,要放在1的后面,再与后半区(有序表:2)的中间值2比较,6>2,6插入到2的后面,得到。第三次比较,从无序表中取出第一个数 7,与中间值2比较,7>2,7放在2后面,再与后半区(有序表:6)的中间值6比较,7>6,7放在6后面,得到。有序表:1,2,6,7;
复分析 阿尔福斯(Ahlfors) 第三版答案 英文
答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案
排序——折半插入排序
折半插入排序是对直接插入排序的改进 ,本篇博客对 折半插入排序的两种实现,尤其对于边界区间考虑的很周到,希望能帮到一起学习的童鞋
jdk-8u144-linux-x64.tar.gz.
该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包
一道排序面试题【20200103】
Java程序如下:public class SortTest { public static void main(String[] args) { int[] a...
C语言Lesson5
// 行列交换, int array[2][3] = {{7, 6, 8},{ 2, 4, 5}}; int array1[3][2] = {0}; for (int i = 0; i 3; i++) { for (int j = 0 ; j 2; j++) { array1[i][j]
扑克牌排序_程序员面试常问算法:插入类排序法
一、算法题目插入类排序法:说白了,就是通过插入方式的排序方法,包括如下直接插入排序、折半插入排序、表插入排序、希尔排序。直接插入排序:类似我们生活中的打扑克启牌的方式。基本思想是:每抓一张牌,插入到合适的位置(在手中的牌需要重头开始比较,直到找到它合适的位置),直到抓完牌为止,从而得到一个连续的有序序列。由于直接插入排序简单且容易理解,下文中不再过多讨论。折半插入排序:如果知道二分法查找,这个也很...
iOS数据结构与算法面试题合集
1、不用中间变量,用两种方法交换A和B的值 // 1.中间变量 void swap(int a, int b) { int temp = a; a = b; b = temp; } // 2.加法 void swap(int a, int b) { a = a + b; b = a - b; a = a - b; } // 3.异或(相同为0,不同为1. 可...
手撕面试题算法<排序>(3.5)—— 希尔排序
前言 之所以把希尔排序作为排序系列的第3.5篇,是因为希尔排序可以称得上是 插入排序Plus ,它在插入排序的基础上继续升级,突破了时间复杂度O(n2)的壁障 手撕算法 - 排序系列 手撕面试题算法<排序>(1)—— 冒泡排序及其优化实现 手撕面试题算法<排序>(2)—— 选择排序 手撕面试题算法<排序>(3)—— 插入排序及其优化实现 源码 看完有收获别忘了点个star哦~ 导航前言手撕算法 - 排序系列源码希尔排序思想例时间复杂度实现测试 希尔排序 思想 希尔排序中,有一个叫做增量的概念,在排序过程
面试-排序-(二)插入排序
一、插入排序:每一趟将一个待排序的元素,按其关键字的大小插入到已排序序列的适当位置,直到全部插入完成。 常见的插入排序有以下三种。 1、直接插入排序 1)过程:直接插入排序是一种最简单的排序方法,其过程就是依次将每个元素插入到一个有序的序列中去。不过它有个缺点,就是当我们的数据基本有序时,每次插入都要移动位置,此时的插入效率是很低的。为了解决这种情况,又产生了拆半插入排序,希尔排序。 工作...
ios笔试题算法_【2018年最新】iOS面试题之算法
1、不用中间变量,用两种方法交换A和B的值// 1.中间变量void swap(int a, int b) {int temp = a;a = b;b = temp;}// 2.加法void swap(int a, int b) {a = a + b;b = a - b;a = a - b;}// 3.异或(相同为0,不同为1. 可以理解为不进位加法)void swap(int a, int b)...
测开面试题--内排序
1. 插入排序:从无序区中顺序选择数据插入到有序区中 - 直接插入排序:在有序去中查找插入位置的方法为顺序查找 public static void insertSort(int[] arr){ for(int i = 1; i < arr.length; i++){ if(arr[i] < arr[i-1]){ //反序时 int tmp = arr[i]; int j = i-1; //找到arr[i]的插入位置 while(j >= 0 &&
iOS 算法面试题(一)
1、不用中间变量,用两种方法交换A和B的值 // 1.中间变量 void swap(int a, int b) { int temp = a; a = b; b = temp; } // 2.加法 void swap(int a, int b) { a = a + b; b = a - b; a = a - b; } // 3.异或(相同为0,不同为1....
8772



被折叠的 条评论
为什么被折叠?



