STL中容器list的sort方法详解

C++ STL中对list中的元素进行排序 阅读详情

**

List 不能使用STL提供的算法 sort() , 必须使用自己定义的sort() member function,因为STL算法sort()只接受RamdonAccessIterator,它的实现代码如下,是一个quick sort;

**

list::sort的代码如下(sgi stl):

template <class _Tp, class _Alloc>  
void list<_Tp, _Alloc>::sort()  
{  
    // Do nothing if the list has length 0 or 1.  
    //以下判断如果是空链表,或者是只有一个元素,就不进行任何操作
    //使用四则size()== 0 || size()== 1来判断,虽然可以但缓慢些
    if (_M_node->_M_next != _M_node && _M_node->_M_nex
STL源码分析:浅析list的sort函数 目录 原理说明 举例说明 总结 虽然STL中提供了标准的sort函数,但是它只适用于随机存取的容器,而显然list并不是这样的容器,因此list提供了专用的链表排序函数,虽然同样名为sort,但是这个sort函数是list类的成员函数。 在分析list的sort函数之前,有必要先简单了解一下list其它几个相关的成员函数。 swap函数:传入参数为一个li... 阅读详情

相关推荐

C++——STL容器之list链表的讲解

简单介绍了C++容器——list的一些内容

weixin_69283129的博客 2200

STL中关于list容器的sort函数详解

写在前面 因为在stl中stl_algo中提供有sort函数,他的函数原型: template &lt;class RandomAccessIterator&gt; inline void sort(RandomAccessIterator first, RandomAccessIterator last); template &lt;class RandomAccessIterator, ...

A_Bo的博客 2698

c++STL常用容器之List容器——排序案例(十七)***排序函数Sort()用法***函数的定义解析***

这里有C++STL——全面总结详细教程(附案例解析)(持续更新中) 目录 排序案例 简言之: 升序用“<”小于号 降序用“>”大于号 排序案例 案例描述:将Person自定义数据类型进行排序,Person中属性有姓名、年龄、身高 排序规则:按照年龄进行升序,如果年龄相同按照身高进行降序 #include<iostream> #include&...

cfl997 8290

STL双向链表list的sort

对于C++的STL的双向链表,排序算法有的模板并没有实现,因此给出来,大家参考。

用易经智慧看懂人工智能:64卦中的科技密码--当古老智慧遇见未来科技

在人工智能狂飙突进的今天,我们总在追问:这些代码构建的智能究竟会带人类走向何方?或许答案早已藏在《周易》的六十四卦中——这本中华文明的“源代码”,正用一种跨越时空的语言,悄悄解释着最前沿的科技秘密。

weixin_38410320的博客 2088

易智联LM401模块学习(四)——双串口收发

串口的发送和接受有三种方式,分别是阻塞发送和接收(轮询)、中断方式发送和接收、DMA方式发送和接收。这里我使用阻塞+中断的方式实现双串口通信。简单的串口收发。

weixin_46046597的博客 997

(二)MS-MPI多机通信

1.关于MPI多机通信 一台计算机处理数据的能力是有限的,MPI的主要作用就是用来实现并行计算机,即将多台主机联机,实现大规模、高性能的计算机机群。我们知道一台计算机同时运行多个进程时,由于计算机资源是共享的,多个进程都会占用一些资源,每个进程运行的效率就会降低,比如当一台计算机同时跑着多个大型应用时会变得非常卡顿。所谓多机通信,可以理解为将本应该在同一台主机上运行的多个进程分配到多台主机上,以往...

xinwuya_的博客 4398

保姆级教程:用STM32CubeMX配置GD32的CAN总线(含异常处理)

本文提供了一份详细的STM32CubeMX配置GD32 CAN总线开发指南,涵盖从HAL库移植到异常处理的全过程。重点解析GD32与STM32在CAN总线初始化、报文发送优先级处理等方面的关键差异,并提供优化代码维护与版本控制的实用策略,帮助开发者高效完成项目迁移。

onion的博客 836

库卡kuka仿真软件sim Pro 3.1简单实用教程

实验目的 建立机器人,自定义抓手,导入外部模型,掌握工具坐标、基坐标的使用,自动生成轨迹。 实验步骤 打开KUKA.Sim Pro 3.1.2仿真软件,依次点击KUKA Sim Library 3.1 → KUKA_ROBOTS→Small Robots(3kg-10kg)→Archiv→AGILUS-1 Series→sixx,双击KR 6 R700 sixx,加载机器臂到工作空间; 加载自定义抓手。双击Miscellaneous,再双击圆锥Cone设置上半径为0,下半径为40,高为100; 点击“捕

weixin_45168199的博客 4万+

word多级列表为什么会变成黑块解决思路

今天在写文档时,发现WORD5级的标题都变黑块了,找了度娘的资料,终于解决了。 第一种 1、光标bai放在黑快的右边,按向左的箭头,然后ctrl+shift+s,点击重新应用。 2、点击“定义新的多级列表”(不知道从哪儿找这个按钮的百度下),直接点确定。 3、这里很重要!!!不要直接保存,而是直接关掉word,会提示保存还是不保存,这个地方再点击保存。 第二种 Word2016 使用宏代码修复方法 1.找到视图-宏,打开 查看宏 2.创建宏 3.贴...

霍力强的专栏 8587

实现端到端加密的WebRTC视频会议终端

需要注意的是,上述示例代码中没有涉及到具体的加密算法和密钥交换过程,而是通过WebRTC API自动处理了加密和密钥交换的细节。然后,我们通过信令服务器将本地SDP发送给对方,并接收对方的SDP。最后,我们将对方的SDP设置为远程描述,并将最终的连接建立起来。最后,我们将对方的SDP设置为远程描述,并建立最终的连接。在本文中,我们将探讨如何使用WebRTC构建一个加密的视频会议终端,并提供相应的源代码。在本文中,我们将探讨如何使用WebRTC构建一个加密的视频会议终端,并提供相应的源代码。

WaJulia的博客 437

NVIDIA Jetson之交叉编译工具

参考:http://bbs.xfyun.cn/forum.php?mod=viewthread&amp;tid=33630 用TX2做红外热成像仪的识别,厂家不提供源码,只能提供对应版本的SDK,但是需要我们自己提供交叉编译器 由于之前没有做过交叉编译相关工作,对编译工具不太了解,因此查找相关资料学习下 交叉编译知识 一般来说,针对嵌入式平台的开发有两种编译模式:原生编译和交叉编译。原生编...

ZONGXP的博客 8391

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

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

Devexpress16.2.6破解工具

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

上一篇: const
下一篇: 虚拟地址相关问题明了解释
山农
博客等级 码龄10年 44粉丝 50原创
评论 3
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值