冒泡两种优化

适航规章、标准,书籍资料下载汇总(更新中) 以下是一些收集到的适航相关的资料,分享给大家。(如果没有你想要的资料,请留言,等找到会及时更新! 阅读详情

https://blog.youkuaiyun.com/hansionz/article/details/80822494

先看冒泡

#include <stdio.h>
#include "string.h"
#include "malloc.h"
#include "iostream"
#include<time.h>
using namespace std;
int table[10]={4,3,7,1,99,55,2,53,44,32};

//遍历数组
void show(int a[],int l,int r )
{
	for(int i=l;i<=r;i++)
	printf("%5d",a[i]);
    printf("\n");
}
 
/*一 :对总趟数进行优化
如果那一趟排序没有交换元素,说明这组数据已经有序,不用再继续下去。

优化1——定义一个flag,用来判断有没有进行交换,如果在某次内层循环中没有交换操作,
就说明此时数组已经是有序了的,不用再进行判断,这样可以节省时间。
*/
void bubble1(int *a,int l,int r)
{
   int i;
   int j=0;
   int flag=1;
   for (j=0;j<=(r-l)&&flag;j++)//控制趟数
   for (i=l;i<r-j;i++)//一趟的冒泡
   {
	   flag=0;
	   if (a[i]>a[i+1])
	   {
		   int temp=a[i+1];
		   a[i+1]=a[i];
		   a[i]=temp;
		   flag=1;  //有比较过程,则置位标志位
	   }
   }
}
void bubble11(int *a,int l,int r)
{
   int i;
   int j=0;
   int flag=1;
   for (j=0;j<=(r-l);j++)
   {
	    for (i=l;i<r-j;i++)
		 {
		   flag=0;
		   if (a[i]>a[i+1])
		   {
			   int temp=a[i+1];
			   a[i+1]=a[i];
			   a[i]=temp;
			   flag=1;  //有比较过程,则置位标志位
		   }
		   if (flag==0)
		   {
			   return;
		   }
		}
   }
  
}

/*第二种是趟内优化 ,记录最后一次交换的位置*/

void bubble2(int *a,int l,int r)
{
   int i;
   int j=0;
   int flag = 0;
    int pos = 0;//用来记录最后一次交换的位置
    int k =r;
   for (j=0;j<=(r-l);j++)
   {
	    pos = 0;
		int i = 0;
		flag = 0;

		for (i=l;i<k;i++)
		{
			flag=0;
			if (a[i]>a[i+1])
			{
			   int temp=a[i+1];
			   a[i+1]=a[i];
			   a[i]=temp;
			   flag=1;  //有比较过程,则置位标志位
			   pos=i;
			}
		}
			if (flag==0)
			{
			   return;
			}
			k=pos;
   }
  
}




void main(){


	 srand( 55 ); 
	 for(int i = 0; i < 10; i++ )  
		 printf( "Random number #%d: %d\n", i, rand() ); 
     
	int *p=(int *)malloc(sizeof(table));
    memcpy(p,table,sizeof(table));
    

	cout<<"=================";
	show(p,0,9);
	cout<<"=================";
	bubble2(p,0,9);

	cout<<"======dd===========";
	show(p,0,9);
	cout<<"=================";
}  

 

 

运动想象 (MI) 分类学习系列 (19) : EEG-TransNet 本文提出了一种基于注意力机制的卷积神经网络(EEG-TransNet),用于运动想象脑电图(MI-EEG)解码。该方法创新性地通过平均池化和方差池化提取多模态时间信息,并结合自注意力模块捕获长期依赖关系。消融实验表明,方差池化比最大池化更有效(p<0.05),且注意力模块和卷积编码器对特征判别性至关重要。可视化分析验证了该方法能学习到更具判别性的紧凑特征。该工作为MI-EEG解码提供了新的多尺度时间信息融合视角,代码已开源。 阅读详情

相关推荐

kettle从入门到精通 第九十二课 ETL之kettle 使用Kettle的Carte对外发布读写接口

场景:使用kettle实现将查询结果返回给客户端,也就是说kettle暴露查询接口供外围系统调用。前提必须是使用carte服务才可以提供接口供外部系统调用。具体实操方法如下:1、设计转换根据具体需求设计转换,主要用到的步骤有获取变量(从请求参数中获取变量)、json输入(解析入参),json 输出将结果转换为json格式输出到客户端。如下图所示:2、接收参数使用获取变量步骤来接收接口请求参数,变量通过${}方法进行获取,如下图${PARAM}则是获取PARAM参数,将参数赋值为req字段。

zhangjin1222的博客 954

如何实现冒泡排序优化,三种优化方式

一、程序描述 冒泡排序(BubbleSort)简单来讲就是通过对其中的元素按顺序两两进行对比,按照规则不断交换,使得一些元素慢慢被换到后面,就像是水中的气泡慢慢的浮出水面(跑到后面)一样。这是一种简单的基于比较大小的排序算法。冒泡排序利用了不等式传递的思想。 算法原理:如果想把某个数组按照递增顺序排列,那么应该从头开始比较相邻的两个元素,如果后面一个元素比前面一个要大,说明顺序不对,就把他们换个位置,直到所有元素全部交换完成,则排序完成。冒泡排序一般用于初学计算机程序设计的人理解算法。 算法稳定性:如果相等

weixin_43738789的博客 6040

保姆级教程:用高云GW2A开发板搭建RISC-V软核处理器(含DDR3内存优化配置)

本文提供了一份详细的保姆级教程,指导开发者使用高云GW2A-LV18PG256C8 FPGA开发板搭建RISC-V软核处理器系统。教程涵盖了从开发环境搭建、PicoRV32软核集成,到关键的DDR3内存控制器配置与优化,并深入讲解了时序约束与系统调试方法,帮助初学者和爱好者实现从逻辑设计到软硬件协同的深度实践。

2a4s6d8f0g的博客 567

冒泡排序优化方案(两种思路)

备考软件设计师时复习到冒泡排序,在这里记录一下对冒泡排序的优化。 先简单聊一下冒泡排序实现: 依次比较数组中相邻两个元素大小,若 a[j] > a[j+1],则交换两个元素,两两都比较一遍称为一轮冒泡,结果是让最大的元素排至最后 重复以上步骤,直到整个数组有序。 ...

weixin_46631108的博客 4743

自动驾驶系统架构解析:从传感器到决策控制的完整链路(附实际案例)

本文深入解析了自动驾驶系统从感知、决策到控制的完整架构链路。通过对比摄像头、毫米波雷达、激光雷达等核心传感器的特性与选型策略,阐述了多传感器融合的必要性。文章结合行为决策、运动规划及控制执行的实际案例,揭示了系统集成、数据闭环与功能安全等工程化落地的关键挑战,为理解自动驾驶技术提供了清晰的蓝图。

weixin_29051811的博客 339

机器学习系列(1)_逻辑回归初步

1、总述 逻辑回归是应用非常广泛的一个分类机器学习算法,它将数据拟合到一个logit函数(或者叫做logistic函数)中,从而能够完成对事件发生的概率进行预测。 2、由来     要说逻辑回归,我们得追溯到线性回归,想必大家对线性回归都有一定的了解,即对于多维空间中存在的样本点,我们用特征的线性组合去拟合空间中点的分布和轨迹。如下图所示:     线性回归能对连续值结果进行预测,

寒小阳 13万+

冒泡排序的三种优化

传统的冒泡排序完全可以满足我们最基本的需求,但是也仅仅是最简单的需求,这种简单的两个for循环不加任何的判断语句的形式注定它只能是一种效率最低的算法。 我们先贴一个传统的实现方式,之后的三个优化全部建立在函数排序所使用的消耗上,这也是我们优化一切算法的根本路径。 void BubbleSort(int* arr,int size) { for(int i=0;i<size;i++) {

hugang的博客 1万+

让Claude连续写代码24小时会发生什么?揭秘长时运行”架构背后的工程逻辑与未来

AI长时运行实验揭示软件开发新范式 Claude Opus通过Harness框架24小时独立开发全栈应用的成功实验,展示了AI从辅助工具向异步协作者的进化。实验采用"上下文轮转"机制解决记忆管理难题,将任务拆解为微周期并通过文件系统同步进度。核心突破在于:1)TDD成为AI自治基石,200+测试用例确保开发不偏航;2)文件取代对话成为AI间高效沟通介质;3)开发者角色重构为需求定义和框架设计者。该实验证明,通过严谨的架构约束和验收标准,AI可完成复杂长周期任务,预示着软件开发将从手工作坊

老孙 | Ethan Sun 的博客:AI 智能体与 AI 原生软件的工程实践 1093

冒泡排序及优化

​ 普通冒泡排序(以升序为例): 依此比较数组中相邻两个元素大小,若a[j]>a[j+1],则交换两个元素,两两都比较一遍称为一轮冒泡,结果是让最大的元素排至最后 重复以上步骤,直到整个数组有序 import java.util.Arrays; public class Task01_BobbleSort { public static void main(String[] args) { int[] a = {5, 9, 7, 4, 1, 3, 2, 8}; //

星空下的那个人影 3349

面向企业级应用的 SAP UI5 troubleshooting 全景指南:从日志与调试到性能与可测试性

本指南系统化介绍了SAP UI5应用排错的完整流程和工具链。从基础的浏览器开发者工具使用,到SAP UI5专用调试工具(Technical Information Dialog、Support Assistant、Diagnostics Window),再到性能优化和日志管理,提供了一套工程化的解决方案。重点推荐组合使用UI5 Inspector扩展、Test Recorder测试工具以及性能测量模块,并强调将常见问题整理成团队知识库。通过制度化的排错步骤和工具组合,开发者可以快速定位、复现和修复问题,将调

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 283

Ardupilot二次开发(二):自定义mavlivk消息

在下面的文件添加自定义消息的xml定义然后编译固件,会生成相应的消息头文件。

超维空间科技的博客 2314

优化冒泡排序!

c语言实现冒泡排序!

Firm的博客 417

RAG 实战:LangChain + 向量数据库构建知识问答系统

从文档加载、分割、嵌入到检索增强生成,完整实现一个基于本地文档的知识问答系统。

kaixin110a的博客 189

冒泡排序及两种优化方式

冒泡排序及两种优化方式

qq_44910471的博客 194

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

冒泡排序算法及其两种优化

冒泡排序算法及其两种优化

qq_44947882的博客 217

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

两种冒泡排序方法以及优化算法

1.向后冒泡图解 代码实现: #include&lt;iostream&gt; using namespace std; //向后冒泡,求出每趟最大值,放到len-1位置 void BubbleSort(int *arr, int len) { int tmp = 0; int i; for (i = 0;i&lt;len-1;i++) { for (int j = 0;j ...

zhangxiafll的博客 518

深度学习工具包 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")

冒泡排序两种优化(笔记)

冒泡排序 冒泡排序(Bubble Sort),是一种较简单的排序算法。 冒泡排序算法的原理如下: 比较相邻的元素。如果第一个比第二个大,就交换他们两个。 对每一对相邻元素做同样的工作,从开始第一对到结尾的最后一对。在这一点,最后的元素应该会是最大的数。 针对所有的元素重复以上的步骤,除了最后一个。 持续每次对end(控制内层循环的循环次数)前面的的元素重复上面的步骤,直到没有任何一对数字需要比较。 冒泡排序算法优化思路: 循环次数优化:当冒泡排序进行外层循环时,内层循环中交换值语句不会再执行(内层循环i

qq_40796888的博客 196

冒泡排序优化 php,冒泡排序及冒泡排序的两种优化

冒泡排序(bubble sort)算法的运作如下:从前往后一次比较相邻的两个元素,如果第二个比第一个元素小,则交换这两个元素,一直到与最后一个元素比较完成,这样最大的元素就放到了最后;这样重复比较(n-1)次即可完成排序。-----------------------------------------------------------------------------------------...

weixin_42298164的博客 187

冒泡排序的两种优化算法

冒泡排序 定义:通俗来说,就是简单的比较相邻的元素,使得元素有序。 package huawei; /** * @author zhang kun * @Classname Sort * @Description TODO * @Date 2021/7/2 19:18 */ public class Sort { public static void main(String[] args) { int[] arr = {2,34,1,3,5,7,4}; i

无 195

两种冒泡排序的比较及冒泡算法优化

第一种: void bubbleSort(int array[],int len){ //循环的次数为数组长度减一,剩下的一个数不需要排序 for(int i=0;i1;++i){ bool noswap=true; //循环次数为待排序数第一位数冒泡至最高位的比较次数 for(int j=0;j1;++j){

coolwriter的博客 439

冒泡排序和其两种优化

第一篇博客 会的算法的也不多 就用c++写个冒泡排序 #include &lt;iostream&gt; #include &lt;iomanip&gt; #include &lt;cstring&gt; #include &lt;cstdio&gt; #include &lt;cstdlib&gt; #include &lt;ctime&gt; using namespace std; ...

EvilKingEyes的博客 264

冒泡排序以及冒泡排序的两种优化

原始冒泡排序图解 不需要排序 进行外层优化的情况 内部需要优化的情况 using System; namespace bubbling { class Program { static void Main(string[] args) { int[] nums = new int[] { 6,7,4,3,2,1 }; ...

破茧 1083

java代码两种写法实现冒泡排序以及冒泡排序的优化

冒泡排序重点在于对给定数字序列的逐对扫描以及交换,其写法并不唯一。一般情况下,外层循环表示扫描的轮数,内层循环表示需要扫描的元素个数。排在最前面的既可以是最大值,也可以是最小值;对给定数据可以顺序扫描,也可以进行逆序扫描,其结果是等效的。对此,我在这里提供了两种写法和一种优化方案与大家分享。 方案一:顺序扫描给定数据,将无序数列中的最大元素依次排到最后。即先冒出最大的气泡 注释掉的代码部分提供...

Hello_MyDream的博客 3万+

冒泡排序算法的两种优化

冒泡排序(三种实现,两种优化) /* 首先,我们先介绍BubbleSort; 就是冒泡排序,冒泡排序大家应该最熟悉不过了; 冒泡排序算法的运作如下:(从后往前) 1. 比较相邻的元素。如果第一个比第二个大,就交换他们两个。 2. 对每一对相邻元素作同样的工作,从开始第一对到结尾的最后一对。在这一点,最后的元素应该会是最大的数。 3. 针对所有的元

John的博客 1万+
上一篇: BSS段
下一篇: (深入理解计算机系统) bss段,data段、text段、堆(heap)和栈(stack) 1
剑之所向
博客等级 码龄11年 228粉丝 110原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值