用数组模拟链表、栈和队列

基于Simulink的鲸鱼优化算法(WOA)MPPT仿真 摘要:本文介绍了基于Simulink的鲸鱼优化算法(WOA)在光伏MPPT控制中的应用。WOA模拟座头鲸的"气泡网捕食策略",通过包围猎物、螺旋收缩和随机搜索三阶段动态平衡全局探索与局部开发能力,有效解决局部阴影导致的多峰P-V曲线问题。文章详细讲解了WOA-MPPT的Simulink建模过程,包括多峰光伏阵列建模、WOA控制器实现和Boost变换器控制。仿真结果显示,在三种典型工况下,WOA-MPPT的追踪效率>99.3%,动态响应时间<0.15s,性能优于传统算法。最后提出了混合WO 阅读详情

2、数据结构

2.1、单链表:主要用作邻接表(存储图、树)

使用数组模拟单链表:

const int N = 100010;
// head存储链表头,
//e[]存储节点的值,
//ne[]存储节点的next指针,
//idx表示当前节点
int head, e[N], ne[N], idx;

//初始化 
void init(){
	head = -1;
	idx = 0;
}

//将x插入到头结点 
void add_to_head(int x){
	e[idx] = x;
	ne[idx] = head;
	head = idx;
	idx ++;
}

//将x插入到下标为 k 的后面 
void add(int k, int x){
	e[idx] = x;
	ne[idx] = ne[k];
	ne[k] =idx;
	idx++;
}

//将第k个数(下标为 k-1)删除  
void remove(int k){
	ne[k] = ne[ne[k]];
} 

2.2、双链表:优化某些问题

const int N =100010;
//e[]存储节点的值,
//l[]存储节点的左指针,
//r[]存储节点的右指针,
//idx表示当前节点
int e[N], l[N], r[N], idx;

void init(){
	// 0表示左端点,1表示右端点
	r[0] = 1, l[1] = 0; 
	idx =2;
}
//在下标是K的右边插入一个 
//在下标为k的左边一个插入一个数 调用 add(l[k],x)即可
void add(int k, int x){
	e[idx] = x;
	r[idx] = r[k];
	l[idx] = k;
	l[r[k]] = idx;
	r[k] = idx;	
	idx++;
	
}

//删除下标为 k 的数 
void remove(int k){
	r[l[k]] = r[k];
	l[r[k]] = l[k];
} 

2.3、栈

用top表示栈顶所在的索引。
初始时,top = -1。表示没有元素。
pusn x :栈顶所在索引往后移动一格,然后放入x。st[++top] = x。
pop : top 往前移动一格。top–
empty :top 大于等于 0 栈非空,小于 0 栈空。top == -1 ? “YES” : “NO”
query : 返回栈顶元素。st[top]

#include <iostream>
using namespace std;

const int N = 100010;

int stack[N], top = -1;
/*
//插入
stk[++ top] = x;

//弹出
top--;

//判断栈是否为空
if(top> 0) not empty;
else empty;

//栈顶
stk[top]; 
*/
int main(){
	
	int m;
	cin>> m;
	while(m--){
		string op;
		int x;
		cin >> op;
		if(op =="push"){
			cin>>x;
			stack[++top] = x;
		
		}else if( op == "pop"){
			--top; 
		}else if( op == "empty"){
			if(top > 0)
				cout << "NO" <<endl;
			else
				cout << "YES" <<endl; 
		}else{
			cout << stack[top]<< endl;
		}
	}
	
	return 0;
} 

2.4、队列

数组模拟普通队列:

#include <iostream>
using namespace std;
const int N = 100010;
// hh 表示队头,tt表示队尾
int q[N], hh = 0, tt = -1;

int main(){
 int m;
 cin>> m;
 while(m--){
 	string op;
 	int x;
 	cin >> op;
 	if ( op == "push") {
 		cin >> x;
 		q[++tt = x;]
	 }else if ( op == "pop") {
	 	hh++;
	 }else if ( op == empty) {
		 	cout<<(hh>tt?"YES":"NO")<<endl;
	 }else {
	 	cout<<q[hh]<<endl;
	 }
 }	
	return 0;
} 

循环队列

// hh 表示队头,tt表示队尾的后一个位置
int q[N], hh = 0, tt = 0;

// 向队尾插入一个数
q[tt ++ ] = x;
if (tt == N) tt = 0;

// 从队头弹出一个数
hh ++ ;
if (hh == N) hh = 0;

// 队头的值
q[hh];

// 判断队列是否为空
if (hh != tt)
{

}

STL中的queue

#include<iostream>
#include<queue>
using namespace std;
const int N=100010;
int n;
int main(){
    queue <int> q;
    cin>>n;
    while(n--){
        string op;
        int x;
        cin>>op;
        if(op=="push"){
            cin>>x;
        	q.push(x);
        }
        else if(op=="pop")
            q.pop();
        else if(op=="empty")
            cout<<(!q.empty()?"NO":"YES")<<endl;
        else
          cout<<q.front()<<endl;
    }
    return 0;
}

单调栈:找出每个数左边离它最近的比它大/小的数
在这里插入图片描述

#include <iostream>
using namespace std;
const int N = 100010;
int n;
int stack[N], tt; //tt为零时 栈为空 
int main(){
	
	cin>> n;
	
	for(int i = 0; i < n; i++){
		
		int x;
		cin>> x;
		
		while( tt && stack[tt] >= x) tt--;
		if(tt)
			cout<< stack[tt] << " ";
		else 
			cout << -1 <<" ";
		stack[++tt] = x;
	}
	
	return 0;
} 

单调队列 :找出滑动窗口中的最大值/最小值
在这里插入图片描述
在这里插入图片描述

#include <iostream>
using namespace std;
const int N = 100010;
int n, k;

//a作为 原数组  q作为队列 存放 下标 
int a[N], q[N];


int main(){
	
	scanf("%d%d",&n, &k);
	
	for(int i = 0; i < n; i++) scanf("%d",&a[i]);
	
	int hh = 0, tt = -1;
	
	for(int i = 0; i < n; i++){
		 //hh > tt  队列为空 ,当队列不为空,且 队头元素 在当前窗口内  
		if(hh <= tt && q[hh]<i-k+1 )
			hh++; //判断队头前元素 是否在当前窗口内 ,如果不在,也要删除 
			
		//当队列不为空 且当前a[i] 小于队列中的数,出队 
		while( hh <=tt && a[q[tt]]>= a[i]) 
			tt--; //从队尾出队 
	
		q[++tt] = i; //入队 
		
		if( i >= k - 1)
			cout<<a[q[hh]]<<" ";
	}
	puts("");	
	
	hh = 0, tt = -1;
	for(int i = 0; i < n; i ++) {
		if(hh <= tt && q[hh]<i-k+1 )
			hh++; 
		while( hh <=tt && a[q[tt]] <= a[i]) 
			tt--; //从队尾出队 
	
		q[++tt] = i; //入队 
		
		if( i >= k - 1)
			cout<<a[q[hh]]<<" ";
	}
	
	return 0;
}

kmp字符串匹配:

#include<iostream>
using namespace std;
const int N = 100010;
const int M = 1000010;
char p[N];
char s[M];

int n, m;
int ne[N];
int main(){
   
    cin>> n >> p + 1 >> m >> s + 1;
    
    //求模式串的next数组: 
    for( int i =2, j = 0; i <= n; i++ ){
    	while( j && p[i] != p[j+1]) j = ne[j];
    	if(p[i] == p[j+1]) j++;
    	ne[i]=j;
	}
    
    //匹配 
    for(int i = 1, j = 0; i <= m; i++){
    	while(j && s[i]!= p[j+1]) j = ne[j];
    	if(s[i] == p[j+1]) j++;
    	if( j == n ){
    		cout << i-n<<" ";
    		j = ne[j];
		}
	}
    
    
    
    return 0;
}
lammps案例:热导率模拟案例讲解(NEMD方法) lammps计算热导率大体可以分为三种方法:EMD、NEMD、rNEMD。 本文介绍非平衡模拟(NEMD)热导率的计算方法。 NEMD下热导率计算公式为: k=dQ*dZ/dt k:热导率 dQ:能量通量。 dT/dZ:温度梯度。 非平衡态下计算热导率的原理是在材料的两端或者中间设置热源和冷源。 在热源输入热量,在冷源抽取等量的热量,在这个过程中计算材料内部会有热量的传递,产生温度梯度。 在lammps模拟中得到能量通量和温度梯度,代入公式即可求得热导率。 热量的输入方式有多种,如fix langevin 阅读详情

相关推荐

EEGLAB安装、EDF数据导入、EEG预处理(Matlab)

目录下载和安装下载安装遇到问题及解决方案导入EDF数据EEG预处理 下载和安装 下载 链接:https://pan.baidu.com/s/17eMT6B7LgZ4PyqWvD5ixmg 提取码:12gz 安装 **第一步:**将下载下来的文件解压,修改名称为eeglab,将此文件夹存放在matlab的安装目录里的toolbox文件夹下,下图是我的路径,需要拷贝到自己相对应的路径中 第二步: 打开Matlab软件,点击主页中的设置路径 设置路径 点击添加并包含子文件夹,将eeglab文件夹添加进来,保

y18771025420的博客 1万+

算法学习Day3——算法基础

一、快速排序(思想:分治) (1)确定分界点x 常用确定分界点方法: Q[L]左边界的点 Q[(R-L)/2]中间的点 Q[R]有边界的点 随机点 (2)调整区间: 划分为两个区间,使小于等于x的数都划分在左边,使大于等于x的数都划分在右边。 (3)递归:递归处理左右两边的值。 暴力求解:有一个简单的做法,但是比较消耗空间。是规定一个数字x,以及初始化两个空的数组,将小于x的值存放在数组a中,大于等于x的值存放于数组b中,之后遍历完后再将ab两个数组的值

Alkaid2000的博客 713

飞牛fnOS安装1Panel后Docker容器消失?三步教你恢复数据并避免踩坑

本文详细解析了飞牛fnOS安装1Panel后Docker容器消失的问题,指出这是由于daemon.json文件被覆盖导致。通过SSH连接、修复配置文件和系统重启三个步骤,用户可以轻松恢复数据。文章还提供了预防措施和最佳实践,帮助用户避免类似问题。

yellow的专栏 891

双指针算法笔记

思想: 例题: 给定一个长度为n的整数序列,请找出最长的不包含重复的数的连续区间,输出它的长度。 输入格式 第一行包含整数n。 第二行包含n个整数(均在0∼105 范围内),表示整数序列。 输出格式 共一行,包含一个整数,表示最长的不包含重复的数的连续区间的长度。 数据范围 1≤n≤105 输入样例: 5 1 2 2 3 5 输出样例: 3 解题代码: #include <iostream> using namespace std; c...

weixin_44798365的博客 269

.ipynb文件深度解析:从JSON结构到Jupyter Notebook高效使用指南

在Python开发与数据处理领域,交互式编程正成为探索数据与验证思路的高效方式。Jupyter Notebook作为最流行的交互式环境之一,其默认文件格式.ipynb本质是一个基于JSON的文本文件,内部通过单元格组织代码、说明文字与运行结果。理解其JSON结构,不仅有助于掌握Notebook的存储原理,更能为文件损坏修复、版本控制与自动化转换提供基础。依托对单元格类型、魔法命令及输出可视化的熟练运用,数据分析和数据可视化流程可以变得更为流畅。同时,借助VS Code、nbconvert等工具,开发者能将.

weixin_28839629的博客 377

XMind文件解析黑科技:用Python实现版本自适应读取(兼容2010-2024)

本文深入探讨了如何利用Python实现XMind文件的版本自适应解析,兼容从2010到2024年的各版本。通过分析XMind文件作为ZIP压缩包的本质,文章提供了智能探测文件内部结构(JSON或XML)并构建健壮读取逻辑的完整方案,有效解决了版本兼容性难题,并演示了将解析数据转换为PlantUML等下游应用的实战案例。

weixin_29041767的博客 694

数据结构表、链表、栈、队列、树的理解

栈是一种遵从后进先出的原则的数据结构在栈中,最后一个入栈的元素是第一个被移除的元素。在队列中,最先添加的元素是第一个被移除的元素。在顺序结构中包括 :线性表、堆栈、队列、字符串、数组等 最经典的常用的是 线性表。满二叉树 是这个树的所有的分支节点都存在左子树和右子树且所有的叶子也在同一层。完全二叉树 是在满二叉树的情况下 叶子在k的或者在k-1的情况下成立。中序的话 就是第一次访问的时候不 查看数据 第二次访问的时候查看数据。后序的话是最后访问的时候查看数据 前两次访问的时候不查看数据。

qq_55337374的博客 804

基于 Matlab 的亚像素边缘检测算法:Zernike 矩

Zernike 矩是一种基于正交多项式的特征提取算法,可以用于分析和描述数字图像中的形状和结构。Zernike 矩可以描述图像在不同方向、不同比例和旋转角度下的变化情况,因此具有很好的不变性和鲁棒性。在基于 Zernike 矩的亚像素边缘检测算法中,我们首先需要将原始图像转换为极坐标系下的图像。然后,对每个像素点,计算其在不同方向下的一阶导数和二阶导数,并将其转换为极坐标系下的形式。其中,“n”表示次数,“m”表示阶数,“rho”和“theta”分别表示极坐标系下的半径和角度。% 转换为极坐标系下的形式。

2301_79325339的博客 987

数据结构--栈、队列、链表、树

常见的数据结构

sugarxxc的博客 640

Umi-OCR 实践教程:离线、免费、高效的图像文字识别工具

Umi-OCR 是一款开源、免费且支持离线运行的 OCR(光学字符识别)工具,适用于 Windows 和 Linux 系统。它基于深度学习技术,能够高效提取图像中的文字,支持多语言识别、批量处理、截屏识别等功能,尤其适合对隐私敏感或网络受限的场景。核心亮点离线运行:无需联网,保护隐私。多引擎支持:提供 Paddle(高性能)和 Rapid(低配兼容)两种引擎。批量处理:支持图片、PDF、电子书等多格式批量识别。跨平台:兼容 Windows 和 Linux(需 Docker 或源码部署)。

xiezhipu的博客 1283

YOLO26涨点改进| TGRS 2026 | 独家创新首发、注意力改进篇| 引入LCGA局部曲率引导注意力,保持局部稳定性的同时突出关键几何区域,含多种创新改进,促进YOLO26所有任务高效涨点

🔥本文提出LCGA(局部曲率引导注意力)模块,通过引入曲率信息改进YOLO26网络模型。LCGA在局部窗口内利用深度卷积构造曲率代理,调制标准窗口注意力,使模型更关注道路、边界等曲线型结构,提升遥感图像超分辨率中的几何保真度。相比普通注意力,LCGA能精准聚焦关键几何区域,减少边缘断裂和轮廓偏移,同时保持较低计算开销。实验表明LCGA显著提升性能,在UCMerced数据集上PSNR提升0.2148dB。文章提供了三种改进方案。

Ai缝合怪、助力小伙伴高效发论文 238

数据结构<6> 并查集

但是在b集合合并到a集合的时候就会发现,此时2000个点的高度+1,因此将节点少的集合,合并到节点多的集合有利于降低查找的时间复杂度。这里因为我们初始化用的是i,所以,数组存储的额外信息,集合的个数就没有了。这里使用的并查集的写法初始情况是全都置为-1的。首先上面的问题我们可以使用朴素算法来接近,就是开一个和人数相同的数组,然后每个人对应一个位置,这个位置存放的数就是代表这个人属于那个集合。按秩合并,意思就是说,要合并两个集合的时候,将元素个数较小的那个结合合并到元素个数较大的那个集合当中去。

qq_62745420的博客 606

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

用数组链表模拟栈和队列

栈和队列,怎么用数组和链表模拟?怎样用c语言实现?本篇文章将会为你详细解答,附带详解。

2601_96917369的博客 271

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

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

《算法基础》数组模拟链表、栈和队列

《算法基础》数组模拟链表、栈和队列 文章目录《算法基础》数组模拟链表、栈和队列前言一. 数组模拟单链表二. 数组模拟双链表三. 数组模拟栈和队列四. 列题:单调栈和单调队列 前言 为什么要用数组来模拟链表,栈和队列那? 这些不是在STL中都有吗 ? 其实一句话, 最主要的原因就是快。 一. 数组模拟单链表 源代码: #include <iostream> #include <algorithm> using namespace std; const int N = 100

qq2297329956的博客 211

vb 6.0并口开发操作实例

vb6并口开发,简体中文,试例内有inpout32.dll动态链接库

用数组模拟链表队列和栈

代码】用数组模拟链表队列和栈。

weixin_51222764的博客 277

队列和栈模拟实现全解析:数组、链表与环形队列

数据结构是计算机科学的核心基础,队列与栈作为最经典的线性结构,分别遵循先进先出与后进先出原则。理解它们的底层实现,需要掌握数组下标与链表指针的运作机制,并解决判空判满、内存释放等工程细节。手动模拟实现队列和栈,不仅能有效规避假溢出、野指针等常见陷阱,还能帮助开发者深入理解消息中间件、线程池和函数调用栈的核心原理。在消息队列、嵌入式缓冲、算法面试等场景中,这些基础能力具有极高的实用价值。本文从零拆解队列与栈的模拟实现,涵盖数组模拟与链表模拟两条主线,并深入探讨环形队列如何解决假溢出,以及阻塞队列在并发环境下的

weixin_31856057的博客 297

数组和链表的区别、ArrayList和LinkedList的区别、使用LinkedList模拟栈和队列

介绍了数组和链表的区别,ArrayList和LinkedList的区别以及使用LinkedList模拟栈和队列。

终生学习践行者 4311

数据结构(二)(用数组模拟栈和队列,单双链表)

1.对于大数据,如果使用new来创建空间,大部分情况是十分耗费时间的,且会超时。因此我们利用数组模拟栈和队列,创建一个数组存储数据的索引,能极快提高运行速率。//0表示左端点,1表示右端点;//将下标为k的点后面的结点删除。

2401_88556637的博客 514

数据结构/算法笔记(2)-数组模拟链表,栈和队列 & KMP算法

静态链表,栈,队列,KMP

u013055171的博客 196

算法学习06-数据结构01:数组模拟:单/双链表,栈和队列,单调栈/队列

💕💕💕。

lenard-lhz的博客 477

数组和vector模拟链表,栈,单调栈,队列,单调队列

acwing算法基础第三天

lihua777的博客 1284

C++数组模拟之单链表与双链表和栈和队列的实现过程

数组模拟链表」是用一块连续的(或内置数组)存放节点,用数组下标代替指针来串联节点。每个节点不再单独new出来,而是占据数组的一个槽位,节点之间的「指针」就是另一个槽位的下标。这种做法在算法题和嵌入式场景里很常见,因为它的访问模式对缓存友好,也不需要为每个节点承担一次动态分配。围绕这个题目,有几个地方容易想歪。第一,认为数组模拟只是「不会用指针的人的替代品」。实际上它在需要大量小节点、频繁增删、又不想承受分配器开销的场合有真实价值。第二,认为用数组就一定没有内存问题。

DO_IT_TODAY的博客 75

模板题——单链表双链表,数组模拟的栈和队列,单调栈和单调队列

1.单链表【数组模拟链式存储结构】 #include <bits/stdc++.h> using namespace std; const int N=100010; int e[N],ne[N]; int head,idx; void init() { head=-1;//头指针 idx=0;//当前空指针 } void add_to_head(int x) { e[idx]=x; ne[idx]=head; head=idx; idx++;

LovelyZhou的博客 241

【算法基础6】链表超时怎么办?用数组模拟(含栈和队列)

用数组模拟单链表、双链表、栈和队列等数据结构,以节省代码运行时间。

qq_52622503的博客 589

【算法基础】单/双链表、栈和队列(用数组模拟)

【算法基础】单/双链表、栈和队列(用数组模拟)

qq_52187526的博客 127

数组模拟链表、栈、队列、单调队、栈

数组模拟链表、栈、队列、单调队、栈——打印资料 数组和链表的优劣对比 参考:https://zhuanlan.zhihu.com/p/73514867 数组的特点: 在内存中,数组是一块连续的区域。 插入和删除数据效率低(插入数据时,这个位置后面的数据都要后移) **查询效率很高。**因为数组是连续的,知道每一个数据的内存地址,可以直接找到给地址的数据(直接索引就能实现,不需要重头遍历)。 不利于扩展,一开始数组定义的空间不够时要重新定义数组。 会造成冗余。空间浪费。 链表的特点: 在内存中,不要求连

马丘 571
上一篇: 传输层协议UDP
下一篇: 网络层IP协议—ipv4
Good_omen
博客等级 码龄7年 95粉丝 71原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值