数据结构篇deque

STL源码剖析(十)序列式容器之deque STL源码剖析(十)序列式容器之deque 文章目录STL源码剖析(十)序列式容器之deque一、deque的数据结构二、deque的迭代器三、deque的操作3.1 构造函数3.2 析构函数3.3 添加元素3.4 删除元素3.5 其他操作 前面我们说的vector是单向开口,而deque是双向开口,也就是保证常数时间在头部和尾部插入元素 一、deque的数据结构 我们先讨论deque是如何实现双... 阅读详情

这篇代码是写给自己看的,所以没什么注释,大家可以去看侯捷先生的《STL 源码剖析》

//mydeque.h
#include"myconstruct.h"
#include"mymemory.h"
using std::max;
using std::copy_backward;
/*deque是双向开头的连续线性空间,它动态地以分段连续空间组合而成,这个表面上deque的迭代器
 *支持随机访问,实则是假象,这里是以复杂的迭代器构架来维持此假象,我学习stl deque的目的是
 *研究它迭代器的构造,而非实用性;
 */
/*deque采用一块map作为主控,这里的map是一小块连续空间,其中的每个元素都是指针,指向另一块
 *连续的线性空间,称为缓冲区,缓冲区是存储主体,允许指定缓冲区的大小,默认情况下为512byte
 */
/*结构                   ——————————————————————————
 *map 指向一段区域|               |node|                                                 |
 *                         ——————————————————————————
 *每个node指向一片连续空间
 */
//BufSiz为缓冲区的大小,意为BufSiz个元素大小
template<typename T,typename Ref,typename Ptr,size_t BufSiz>
struct __deque_iterator
{
	typedef __deque_iterator<T,T&,T*,BufSiz>  iterator;
	typedef __deque_iterator<T,const T&,const T*> const_iterator;
	static size_t buffer_size(){return __deque_buf_size(BufSize,sizeof(T))};

	typedef random_iterator_tag iterator_category;
	typedef T                             value_type;
	typedef Ptr                           pointer;
	typedef Ref                           reference;
	typedef size_t                       size_type;
	typedef ptrdiff_t                    difference_type;
	typedef T**                          map_pointer;

	typedef __deque_iterator   self;
	//保持与容器的联结
	T* cur;//所指元素;这里的cur依然保持迭代器特征,如果在最前端,则指向最前端元素,
	//如果在最后端指向最后端的下一个元素
	T* first;//所指元素所在的缓冲区的头
	T* last;//所指元素所在的缓冲区的尾
	map_pointer node;//指向这一缓冲区的在map中的节点位置

private:
	//辅助函数
	void set_node(map_pointer new_node)//切换node
	{
		node=new_node;
		first=*new_node;
		last=first+difference_type(buffer_size());
	}
public:
/*---------------------重载的操作符-------------------------------------------*/
	//必要的操作符
	reference operator*() const {return *cur;}
	pointer    operator->() const {return &(operator*());}

	self& operator++()
	{++cur;if(cur==last){set_node(node+1);cur=first;} return *this;}
	self  operator++(int)
	{self tmp=*this;++*this;return tmp;}

	self& operator--()
	{if(cur==first){set_node(node-1);cur=last;} --cur;return *this;}
	self operator--(int)
	{self tmp=*this;--*this;return tmp;}
	
	//支持随机存取的实现
	difference_type operator-(const self& x) const
	{return difference_type(buffer_size())*(node-x.node-1) + (cur-first)+(x.last-x.cur);}

	self& operator+=(difference_type n);
	self   operator+(difference_type n) const 
	{self tmp=*this;return tmp+=n;}

	self& operator-=(difference_type n){return *this+=-n;}
	self   operator-(difference_type n)const {self tmp=*this;return tmp-=n;}

	reference operator[](difference_type n)const {return *(*this+n);}

	//判断操作符
	bool operator==(const self& x) const{return cur==x.cur;}
	bool operator!=(const self& x) const {return !(*this==x);}
	bool operator<(const self& x)const
	{return (node==x.node)?(cur<x.cur):(node<x.node);}




};
//全局函数,如果n不为0,那么返回n;如果n为0,那么使用默认值512byte,返回值为512/sz
inline size_t __deque_buf_size(size_t n,size_t sz)
{
	return (n!=0)?n :(  (sz<512)?size_t(512/sz):size_t(1));
}
//---------------------------------------------------------------------------
template<typename T,typename Ref,typename Ptr,size_t BufSiz>
typename __deque_iterator<T,Ref,Ptr,BufSiz>::self& 
	__deque_iterator<T,Ref,Ptr,BufSiz>::operator+=(difference_type n)
{
	difference_type offset=n+(cur-first);
	if(offset>=0 && offset<difference_type(buffer_size()))
		//还在原缓冲区中
			cur+=n;
	else{
		//不在原缓冲区中,此处的计算较复杂
		difference_type node_offset=offset>0?offset/difference_type(buffer_size())
			:-difference_type((-offset-1)/buffer_size())-1;
		set_node(node+node_offset);
		cur=first+(offset-node_offset*difference_type(buffer_size()));
	}
	return *this;
}
//-------------------------------------------------------------------------------------------

template<typename T,typename Alloc=alloc,size_t BufSiz=0>
class deque
{
public:
	typedef T value_type;
	typedef value_type* pointer;
	typedef size_t     size_type;
	typedef const value_type* const_pointer;
	typedef value_type&  reference;
	typedef const value_type& const_reference;
	typedef ptrdiff_t  difference_type;
	
	typedef __deque_iterator<T,T&,T*,BufSiz>   iterator;
protected:
	//元素的指针的指针
	typedef pointer* map_pointer;
	//Data member
	size_type  map_size;//map所指区域的大小
	map_pointer map;
	iterator start;//第一个节点,用iterator包含缓冲区的信息
	iterator finish;//last迭代器
protected:
	//配置缓冲区中的元素
	typedef simple_alloc<value_type,Alloc>  data_allocator;
	//配置map中的元素,即node
	typedef simple_alloc<pointer,Alloc>   map_allocator;

public:
	deque(int n,const value_type& value)
		:map_size(0),start(),finish(),map(0){fill_initialize(n,value);}

	iterator begin(){return start;}
	iterator end(){return finish;}
	size_type buffer_size(){return iterator::buffer_size();}
	reference operator[](size_type n){return start[difference_type(n)];} 
	reference front(){return *start;}
	reference back()
	{iterator tmp=finish;--tmp;return *tmp;}
	size_type size() const {return finish-start;}
	size_type max_size() const {return size_type(-1);}//什么意思?
	bool empty() const {return finish==start;}
public:
	void push_back(const value_type& t);
	void push_front(const value_type& t);
	void pop_back();
	void pop_front();
	void clear();//清除元素,最后留一个缓冲区
	iterator erase(iterator pos);
	iterator insert(iterator position,const value_type& x);
private:
	//辅助函数
	void fill_initialize(size_type n,const value_type& value);
	void create_map_and_node(size_type num_elem);
	value_type* allocate_node();//分配一个缓冲区
	void deallocate_node(value_type* p);//释放一个缓冲区

	void push_back_aux(const value_type& t);
	void push_front_aux(const value_type& t);
	void pop_back_aux();
	void pop_front_aux();

	iterator insert_aux(iterator pos,const value_type& x);
	//以下三个函数解决:什么时候map需要重新整治?
	void reserve_map_at_back(size_type nodes_to_add=1);
	void reserve_map_at_front(size_type nodes_to_add=1);
	void reallocate_map(size_type nodes_to_add,bool add_at_front);

};
//----------------------------------------------------------------------------------------------
template<typename T,typename Alloc,size_t BufSiz>
void deque<T,Alloc,BufSiz>::fill_initialize(size_type n,const value_type& value)
{
	create_map_and_nodes(n);
	map_pointer cur;
	for(cur=start.node;cur<finish.node;++cur)
		uninitialized_fill(*cur,*cur+buffer_size(),value);
	//最后一个节点的值设定:
	uninitialized_fill(finish.first,finish.cur,value);
}
//------------------------------------------------------------------------------------------------
template<typename T,typename Alloc,size_t BufSiz>
deque<T,Alloc,BufSiz>::value_type*  deque<T,Alloc,BufSiz>::allocate_node()
{
	return data_allocator::allocate(buffer_size());
 }
//--------------------------------------------------------------------------------------------------
template<typename T,typename Alloc,size_t BufSiz>
void deque<T,Alloc,BufSiz>::deallocate_node(value_type* p)
{
	data_allocator::deallocate(buffer_size());
}
//------------------------------------------------------------------------------------------------
template<typename T,typename Alloc,size_t BufSiz>
void deque<T,Alloc,BufSiz>::create_map_and_node(size_type num_elem)
{
	//需要的map节点数:元素个数/每个缓冲区可容纳的元素数  +1
	size_type num_node=num_elem/buffer_size()+1;
	//一个map要管理的结点数最少是8个,最多是所需结点数加2,(前后各预留一个)
	map_size=max(8,num_node+2);
	map=map_allocator::allocate(map_size);
	//map配置完毕

	//令map从中央开始扩增
	map_pointer nstart=map+(map_size-num_node)/2;
	map_pointer nfinish=nstart+num_node-1;
	map_pointer cur;
	try{
		//为每个节点配置缓冲区
		for(cur=nstart;cur<=nfinish;++cur)
			*cur=allocate_node();
	}catch(...){
		//commit or rollback
		for(cur=nstart;cur!=NULL;++cur)
			deallocate_node(*cur);
	}
	start.set_node(nstart);
	finish.set_node(nfinish);
	start.cur=start.first;
	finish.cur=finish.first+num_elem%buffer_size();
}
//-----------------------------------------------------------------------------------------
template<typename T,typename Alloc,size_t BufSiz>
void deque<T,Alloc,BufSiz>::push_back(const value_type& t)
{
	if(finish.cur!=finish.last-1){
		//最后缓冲区还有两个以上的备用空间
		construct(finish.cur,t);
		++finish.cur;
	}else{
		//只剩一个元素的备用空间
		push_back_aux(t);
	}
}
//----------------------------------------------------------------------------------------
template<typename T,typename Alloc,size_t BufSiz>
void deque<T,Alloc,BufSiz>::push_back_aux(const value_type& t)
{
	value_type t_copy=t;
	reserve_map_at_back();//若符合某种条件则必须重换一个map
	*(finish.node+1)=allocate_node();
	try{
	construct(finish.cur,t_copy);
	finish.set_node(finish.node+1);
	finish.cur=finish.first;
	}catch(...){
		finish.set_node(finish.node-1);
		finish.cur=finish.last-1;
		deallocate_node(*(finish.node+1));
		throw;
	}
}
//------------------------------------------------------------------------------------------
template<typename T,typename Alloc,size_t BufSiz>
void deque<T,Alloc,BufSiz>::push_front(const value_type& t)
{
	if(start.cur!=start.first){
		construct(start.cur-1,t);
		--finish.cur;
	}else{
		push_front_aux(t);
	}
}
//---------------------------------------------------------------------------------------------
template<typename T,typename Alloc,size_t BufSiz>
void deque<T,Alloc,BufSiz>::push_front_aux(const value_type& t)
{
	value_type t_copy=t;
	reserve_map_at_front();
	*(start.node-1)=allocate_node();
	try{
		start.set_node(start.node-1);
		start.cur=start.last-1;
		construct(start.cur,t_copy);
	}catch(...){
		//commit or rollback
		start.set_node(start.node+1);
		start.cur=start.first;
		deallocate_node(*(start.node-1));
		throw;
	}
}
//-------------------------------------------------------------------------------------
template<typename T,typename Alloc,size_t BufSiz>
void deque<T,Alloc,BufSiz>::reserve_map_at_back(size_type nodes_to_add=1)
{
	if(nodes_to_add+1>map_size-(finish.node-map)){
		//尾部空间不足,需要换一个map
		reallocate_map(nodes_to_add,false);
	}
}
//----------------------------------------------------------------------------------------
template<typename T,typename Alloc,size_t BufSiz>
void deque<T,Alloc,BufSiz>::reserve_map_at_front(size_type nodes_to_add=1)
{
	if(nodes_to_add>start.node-map){
		reallocate_map(nodes_to_add,true);
	}
}
//------------------------------------------------------------------------------------------
template<typename T,typename Alloc,size_t BufSiz>
void deque<T,Alloc,BufSiz>::reallocate_map(size_type nodes_to_add,bool add_at_front)
{
	size_type old_num_nodes=finish.node-start.node+1;
	size_type new_num_nodes=old_num_nodes+nodes_to_add;

	map_pointer new_nstart;
	if(map_size>2*new_num_nodes){
		new_nstart=map+(map_size-new_num_nodes)/2+(add_at_front?nodes_to_add:0);
		if(new_nstart<start.node)
			copy(start.node,finish.node+1,new_nstart);
		else
			copy_backward(start.node,finish.node+1,new_nstart+old_num_nodes);
	}else{
		size_type new_map_size=map_size+max(map_size,nodes_to_add)+2;
		//配置新空间
		map_pointer new_map=map_allocator::allocate(new_map_size);
		new_nstart=new_map+(new_map_size-new_num_nodes)/2+(add_at_front?nodes_to_add:0);
		copy(start.node,finish.node+1,new_nstart);
		map_allocator::deallocate(map,map_size);
		map=new_map;
		map_size=new_map_size;
	}
	start.set_node(new_nstart);
	finish.set_node(new_nstart+old_num_nodes-1);
}
//-----------------------------------------------------------------------------------------------
template<typename T,typename Alloc,size_t BufSiz>
void deque<T,Alloc,BufSiz>::pop_back()
{
	if(finish.cur!=finish.first){
		--finish.cur;
		destroy(finish.cur);
	}else{
		pop_back_aux();
	}
}
//---------------------------------------------------------------------------------------------
template<typename T,typename Alloc,size_t BufSiz>
void deque<T,Alloc,BufSiz>::pop_back_aux()
{
	deallocate_node(*(finish.node));
	finish.set_node(finish.node-1);
	finish.cur=finish.last-1;
	destroy(finish.cur);
}
//-----------------------------------------------------------------------------------------
template<typename T,typename Alloc,size_t BufSiz>
void deque<T,Alloc,BufSiz>::pop_front()
{
	if(start.cur!=start.last-1){
		destroy(start.cur);
		++start.cur;
	}else{
		pop_front_aux();
	}
}
//---------------------------------------------------------------------------------------
template<typename T,typename Alloc,size_t BufSiz>
void deque<T,Alloc,BufSiz>::pop_front_aux()
{
	destroy(start.cur);
	deallocate_node(*(start.node));
	start.set_node(start.node+1);
	start.cur=start.first;
}
//-----------------------------------------------------------------------------------------
template<typename T,typename Alloc,size_t BufSiz>
void deque<T,Alloc,BufSiz>::clear()
{
	for(map_pointer node=start.node+1;node<finish.node;++node){
		destroy(*node,*node+buffer_size());
		deallocate_node(*(node));
	}
	if(start.node!=finish.node){
		destroy(start.cur,start.last);
		destroy(finish.first,finish.cur);
		deallocate_node(*(finish.node));
	}else{//只有一个缓冲区
		destroy(start.cur,finish.cur);//析构所有元素
		finish=start;
	}
}
//-------------------------------------------------------------------------------------------
template<typename T,typename Alloc,size_t BufSiz>
typename deque<T,Alloc,BufSiz>::iterator deque<T,Alloc,BufSiz>::erase(iterator pos)
{
	iterator next=pos;
	++next;
	difference_type  index=pos-start;
	if(index<(size()>>1)){//清除元素之前的元素比较少
		copy_backward(start,pos,next);
		pop_front();
	}else{
		copy(next,finish,pos);
		pop_back();
	}
	return start+index;
}
//---------------------------------------------------------------------------------
template<typename T,typename Alloc,size_t BufSiz>
typename deque<T,Alloc,BufSiz>::iterator 
	deque<T,Alloc,BufSiz>::insert(iterator position,const value_type& x)
{
	if(position.cur==start.cur){
		push_front(x);
		return start;
	}else if(position.cur==finish.cur){
		push_back(x);
		iterator tmp=finish;
		--tmp;
		return tmp;
	}else{
		return insert_aux(position,x);
	}
}
//-----------------------------------------------------------------------------------
template<typename T,typename Alloc,size_t BufSiz>
typename deque<T,Alloc,BufSiz>::iterator 
	deque<T,Alloc,BufSiz>::insert_aux(iterator pos,const value_type& x)
{
	difference_type index=pos-start;
	value_type x_copy=x;
	if(index<size()/2){
		push_front(front());
		iterator front1=start;
		++front1;
		iterator front2=front1;
		++front2;
		pos=start+index;
		iterator pos1=pos;
		++pos1;
		copy(front2,pos1,front1);
	}else{
		push_back(back());
		iterator back1=finish;
		--back1;
		iterator back2=back1;
		--back2;
		pos=start+index;
		copy_backward(pos,back2,back1);
	}
	*pos=x_copy;
	return pos;
}


集合Collection(List、Set、Deque),Map,Comparator与Comparable 1、Collection 1.1 1.2 功能介绍 Collection是一个顶层接口,不能被实例化,其功能可分为: a) 根接口Collection的常用子接口 List接口实现类:ArrayList、Vector、LinkedList Set接口实现类:HashSet、TreeSet b) 添加功能 boolean add(object obj)添加一个元素 boolean addAll(Collection c)将集合c的全部元素添加到原集合元素后返回true 添加功能永远返回true 阅读详情

相关推荐

lvgl 实现表格table,并且固定表头

嵌入式实现table,lvgl 实现原生表格table组件

m0_61704502的博客 1271

STL详解(五) 双端队列容器deque

一、deuqe简介 1、deuqe概念 容器deque和vector非常相似,属于序列式容器。都是采用动态数组来管理元素,提供随机存取,并且有着和vector一样的接口。不同的是deque具有首尾两端进行快速插入、删除的能力。 2、Deque结构 如图1是deque的逻辑结构,从表面上看,deque具有连续性的存储空间,并支持随机存取功能。实际上deque并...

流年的博客 4086

VMvare 桥接模式无法联网、没有未桥接的主机网络适配器,无法将网络更改为桥接状态。

很多程序员,整天沉浸在业务代码的 CRUD 中,业务中没有大量数据做并发,缺少实战经验,对并发仅仅停留在了解,做不到精通,所以总是与大厂擦肩而过。我把私藏的这套并发体系的笔记和思维脑图分享出来,理论知识与项目实战的结合,我觉得只要你肯花时间用心学完这些,一定可以快速掌握并发编程。《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!战项目源码讲义》点击传送门即可获取!**

q16974058的博客 4330

【数据结构】双端队列

定义 deque(double-ended queue,双端队列)是一种具有队列和栈的性质的数据结构。双端队列中的元素可以从两端弹出。 结构示意图 首先每个节点包含一个存储的元素和一个指向下一节点的指针。整个双端队列则只包含一个头(head)节点的指针和一个尾(tail)节点的指针。头节点指向链表的第一个元素,尾节点指向最后一个元素。 定义的代码 struct Node{ T elem; struct Node * next; }; typedef struct Deque{ struct Node

SWELER的博客 1286

数值天气预报期末复习

数值天气预报期末复习

m0_60394632的博客 7679

从零开始理解固定翼能量控制:Pixhawk TECS算法保姆级教程

本文深入解析了Pixhawk飞控中的TECS(总能量控制)算法,旨在解决固定翼无人机纵向控制中速度与高度耦合的经典难题。教程从物理概念出发,阐释了TECS通过管理总能量与分配能量形态来实现油门与升降舵解耦的核心思想,并提供了参数调试的实战指南,帮助开发者优化飞行性能。

white的博客 250

数据结构之deque双端队列

下标随机访问,效率不错,但是跟vector有差距中间插入删除,效率差头插、头删、尾插、尾删效率很不错。所以在容器适配的选择上,什么情况选择deque呢,在头插、头删、尾插、尾删比较多的情况下,可以选择deque。但是如果对中间位置访问比较多,比如优先级队列(本质是堆),就不能选择deque,应该选择vector(性能上差很多!

可涵的博客 707

【报错解决】OpenClaw 报错 `openclaw: command not found`:全局命令未加入系统 PATH 的深度排查与修复指南

在国产AI工具链开发中,OpenClaw作为关键命令行工具常出现command not found报错。本文深度分析该问题的根源——Linux环境变量PATH未包含用户级安装目录(~/.local/bin)。通过四种解决方案(临时PATH修改、永久配置、软链接、虚拟环境处理)和排错Checklist,揭示"命令存在却找不到"的本质是路径配置问题,特别适用于Docker/国产Linux/非root环境。文中强调理解Linux工具链机制对国产AI开发的重要性,并指出这是开发者掌握环境

博客 5382

【C++STL】deque的结构和使用

deque是由一块一块的固定大小的连续空间构成(块与块之间是不连续的)。一旦有必要在deque的前端或者尾端增加新的空间,便配置一块固定大小的连续空间,串接在整个deque的头端或者尾端。deque 的最大任务,便是在这些分块的固定大小连续空间上,维护其整体连续的假象,并提供随机存取的接口(随机迭代器),代价则是迭代器架构较为复杂。deque 采用一块所谓的_M_map(不是STL的map容器)作为主控。

weixin_52958292的博客 855

2025年CSP-J复赛真题及题解:T4 多边形(polygon)

2025年CSP-J复赛真题及题解:T4 多边形(polygon)

王老师青少年编程 1718

HTML爱心字母雨(完整代码)

HTML语言实现爱心字母雨的完整代码。

AIGC 2万+

序列容器之Deque

序列容器之Deque vector是单向开口的连续线性空间,deque则是一种双向开口的连续线性空间。所谓双向开口,意思是可以在头尾两端分别做元素的插人和删除操作,如图所示。 deque的迭代器也是Random Access Iterator。设计比较复杂。deque和vector的最大差异,一在于deque允许于常数时间内对起头端进行元素的插入或移除操作,二在于deque没有所谓

lcf枫的博客 364

【Bug已解决】NCCL timeout for validation 解决方案

训练用多卡 DDP / FSDP 正常,但一到或者进程直接 hang 在 eval 的某个集合通信上。最迷惑的是:训练阶段(有集合通信)完全正常,偏偏 eval 阶段(看起来更轻量)超时。因为 eval 阶段某些 rank 没参与 collective,导致参与的那部分 rank 永远等不到同伴。

一键难忘的博客 142

python collections deque_python collections 模块 之 deque

classcollections.deque(iterable[,maxlen]):返回 由可迭代对象初始化的 从左向右的 deque 对象。maxlen: deque 的最大长度,一旦长度超出,会在 相反方向 删除等量的 items。append(x): 从 deque 的右边添加appendleft(x): 从 deque 的左边添加clear(): 移除 deque 中的所有元素copy(...

weixin_33941707的博客 245

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

STL---deque---学习

定义: deque 即双端队列。(deque,全名double-ended queue)是一种具有队列和栈的性质的数据结构。双端队列中的元素可以从两端弹出,其限定插入和删除操作在表的两端进行。 双端队列是限定插入和删除操作在表的两端进行的线性表。这两端分别称做端点1和端点2。也可像栈一样,可以用一个铁道转轨网络来比喻双端队列。在实际使用中,还可以有输出受限的双端队列(即一个端点允许插入和删除

crisy1991的博客 423

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

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

NC14661 简单的数据结构

因为要从队头队尾插入删除元素,可以用STL中的deque(双端队列)便于操作. 这些是deque的一些基本操作: 1.把x压入后/前端:push_back(x)/push_front(x) 2.访问(不删除)后/前端元素:back()/front() 3.删除后/前端元素:pop_back() pop_front() 4.判断deque是否空:empty() 5.返回deque的元素数量:size() 6.清空deque:clear() 7.排序:sort(d.begin(),d.end()) #inclu

qq_41854014的博客 268

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

6-3 Deque

deque

jokersboost的博客 176

python双向链表库_python deque的内在实现 本质上就是双向链表所以用于stack、队列非常方便...

前言:在 Python 生态中,我们经常使用 collections.deque 来实现栈、队列这些只需要进行头尾操作的数据结构,它的 append/pop 操作都是 O(1) 时间复杂度。list 的 pop(0) 的时间复杂度是 O(n), 在这个场景中,它的效率没有 deque 高。那 deque 内部是怎样实现的呢? 我从 GitHub 上挖出了 CPython collections 模...

weixin_30899991的博客 435

Java中构建stack和deque

用于构造栈或队列 Deque<Integer> temp = new ArrayDeque<>(); temp.push()在尾部追加元素 temp.poll()在头部弹出元素(作为队列) temp.pop()在尾部弹出元素(作为栈)

weixin_46515047的博客 348

python实验:1.两个列表对应元素相乘;2.测试List和deque时间对比测试

1、实现两个列表对应元素相乘,结果生成一个新的列表,两个列表的元素为10个,每个元素均用random下面的randint生成随机整数,randint传入两个参数,分别为生成随机整数的下界和上界

qq_38988221的博客 3640

Java Collections中各种数据结构的使用总结

未完待续

温迪今天刷题了吗 204

【初阶与进阶C++详解】第十一篇:stack+queue+priority_queue+deque(仿函数)

和queue一样都是属于头文件< queue >优先级队列就是一个堆,默认是大堆,有关堆知识的传送门构造一个空的优先级队列empty( )检测优先级队列是否为空,是返回true,否则返回 falsetop( )返回优先级队列中最大(最小元素),即堆顶元素push(x)在优先级队列中插入元素xpop()删除优先级队列中最大(最小)元素,即堆顶元素while(!}

YQ20210216的博客 1009

6-1 Deque (20 分)

6-1 Deque (20 分) A “deque” is a data structure consisting of a list of items, on which the following operations are possible: Push(X,D): Insert item X on the front end of deque D. Pop(D): Remove the front item from deque D and return it. Inject(X,D): Inser

HHLucifer的博客 213

简单的数据结构_via牛客网

栗酱有一天在网上冲浪的时候发现了一道很有意思的数据结构题。 该数据结构形如长条形。 一开始该容器为空,有以下七种操作。 1 a从前面插入元素a 2 从前面删除一个元素 3 a从后面插入一个元素 4 从后面删除一个元素 5 将整个容器头尾翻转 6 输出个数和所有元素 7 对所有元素进行从小到大排序

xjsc01的博客 177

PTA deque

A “deque” is a data structure consisting of a list of items, on which the following operations are possible: Push(X,D): Insert item X on the front end of deque D. Pop(D): Remove the front item from deque D and return it. Inject(X,D): Insert item X on the r

m0_51312071的博客 349

C++栈和队列之(deque)模拟实现

#include<iostream> #include<vector> #include<stack> #include<queue> #include<deque> #include<algorithm> using namespace std; namespace bit { #include<deque> template<class T, class Con = deque<T>>

weixin_45806964的博客 409
上一篇: 算法导论数据结构篇---vector
下一篇: 第十六篇--算法导论排序篇总结-开发实用quicksort算法
wangyanphp
博客等级 码龄14年 90粉丝 51原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值