STL中的list以及简单实现

news2024/9/25 10:24:06

STL的list的底层结构其实就是带头双向循环双向链表

带头双向循环双向链表又简单又好用,效率又高,所以其结构是完美的(对于链表而言):

其中一个原因:有哨兵位的头节点,又循环,找尾很方便,也就是有着O(1)的时间复杂度的插入删除

1.list的构造:

(constructor)构造函数声明

接口说明

list (size_type n, const value_type& val = value_type())
构造的 list 中包含 n 个值为 val 元素

list()

构造空的 list
list (const list& x)
拷贝构造函数
list (InputIterator first, InputIterator last)
[first, last) 区间中的元素构造 list

2.list iterator的使用  

函数声明

接口说明

begin +  end
返回第一个元素的迭代器 + 返回最后一个元素下一个位置的迭代器
rbegin + rend
返回第一个元素的 reverse_iterator, end 位置 返回最后一个元素下一个位 置的 reverse_iterator, begin 位置

说到迭代器遍历的话,与string,vector都一样;

list<int> lt;
lt.push_back(1);
lt.push_back(2);
lt.push_back(3);
lt.push_back(4);

list<int>::iterator it = lt.begin();
while (it != lt.end())
{
	cout << *it << " ";
}
cout << endl;

for (auto e : lt)
{
	cout << e << " ";
}
cout << endl;

是否还支持下标+【】? list就没有支持方括号了:
比如说从第一个开始到size,下标倒是能想办法获取,但是方括号不支持了,支持 operator [ ] 的话,成本会很高,比如说我要获取我的第3个数据,第5个数据,我是不是得从头开始挨着挨着往后才能遍历获取到第3个,第5个?从功能上来说,从可行性上来说,可以实现的。这个角度来说,语法支持,那它是可以实现 operator [ ] 的。只不过 list 的 operator [ ] 是O(N),但是之前像string,vector 的 operator [ ] 是O(1),因为之前像数组这种结构呢,它是连续的物理空间,想获取第几个的话,它的物理空间是连续的,我有指向,你开始的指针,你想获取第二个我是不是加a就过去了,对不对?但是这个地方这些链表呢,它的底层的这些节点呢都是不连续的,你加I你就加不过去,在这个地方,所以我们在这呢是不能这样玩的,不支持 operator [ ] 的。 

链表:(空间展示)

数组: (空间展示)

可以看出:list的迭代器的实现就不再是原生指针了:(不支持+/-)

#include<iostream>
#include<list>

using namespace std;

int main()
{
	list<int> lt;
	lt.push_back(1);
	lt.push_back(2);
	lt.push_back(3);
	lt.push_back(4);

	list<int>::iterator it = lt.begin();
	lt.erase(it + 3);//二进制“+”:“std::_List_iterator<std::_List_val<std::_List_simple_types<_Ty>>>”不定义该运算符或到预定义运算符可接收的类型的转换

	return 0;
}

扩展:不同结构带来的各自不同所属迭代器的性质区别 

决定了可以使用那些算法 :

void test_list1()
{
	list<int> lt;
	lt.push_back(1);
	lt.push_back(2);
	lt.push_back(3);
	lt.push_back(4);
	list<int>::iterator it = lt.begin();
	// 不支持,算法中的sort要求随机迭代器
	//sort(lt.begin(), lt.end());



	string s("dadawdfadsa");
	cout << s << endl;
	//string的迭代器就能被支持
	sort(s.begin(), s.end());
	cout << s << endl;
}
【注意】
1. begin end 为正向迭代器,对迭代器执行 ++ 操作,迭代器向后移动
2. rbegin(end) rend(begin) 为反向迭代器,对迭代器执行 ++ 操作,迭代器向前移动

3.list capacity:

函数声明

接口说明

empty
检测 list 是否为空,是返回 true ,否则返回 false
size
返回 list 中有效节点的个数

4.list element access:

函数声明

接口说明

front
返回 list 的第一个节点中值的引用
back
返回 list 的最后一个节点中值的引用

5.list modifiers:

函数声明

接口说明

push_front
list 首元素前插入值为 val 的元素
pop_front
删除 list 中第一个元素
push_back
list 尾部插入值为 val 的元素
pop_back
删除 list 中最后一个元素
insert
list position 位置中插入值为 val 的元素
erase
删除 list position 位置的元素
swap
交换两个 list 中的元素
clear
清空 list 中的有效元素

其实list库中还有一个接口:emplace_back 与push_back功能类似,但是emplace_back的效率相对较高,而且,emplace_back支持直接传构造对象的参数:

	list<A> lt;
	A aa1(1, 1);
	lt.push_back(aa1);
	lt.push_back(A(2, 2));
	//lt.push_back(3, 3);不支持直接传构造A对象的参数

	lt.emplace_back(aa1);
	lt.emplace_back(A(2, 2));
	cout << endl;
	//支持直接传构造A对象的参数emplace_back
	lt.emplace_back(3, 3);

算法库中还有自己定义实现的sort(底层是归并){因为算法库的sort(底层主要是快排,递归深度过大才会选择堆排)不支持list结构(于swap基本一样的处境)},而且sort都是默认升序 。如果想实现降序的话要用到仿函数(greater这个模板):

list<int> lt;
lt.push_back(1);
lt.push_back(20);
lt.push_back(3);
lt.push_back(5);
lt.push_back(4);
lt.push_back(5);
lt.push_back(6);

for (auto e : lt)
{
	cout << e << " ";
}
cout << endl;

// 升序
lt.sort();

// 降序 - 仿函数
// less<int> ls;
// greater<int> gt;
// lt.sort(gt);
lt.sort(greater<int>());//使用匿名对象

但是,list中的sort的效率并不是很高,下面我们拿vector与其对比:

注意:要在release版本,不要在debug版本下对比两者,因为debug没有优化,可能起不到公平的对比:

void test_op1()
{
	srand(time(0));
	const int N = 1000000;

	list<int> lt1;
	vector<int> v;

	for (int i = 0; i < N; ++i)
	{
		auto e = rand() + i;
		lt1.push_back(e);
		v.push_back(e);
	}

	int begin1 = clock();
	// 排序
	sort(v.begin(), v.end());
	int end1 = clock();

	int begin2 = clock();
	lt1.sort();
	int end2 = clock();

	printf("vector sort:%d\n", end1 - begin1);
	printf("list sort:%d\n", end2 - begin2);
}

void test_op2()
{
	srand(time(0));
	const int N = 1000000;

	list<int> lt1;
	list<int> lt2;

	for (int i = 0; i < N; ++i)
	{
		auto e = rand()+i;
		lt1.push_back(e);
		lt2.push_back(e);
	}

	int begin1 = clock();
	// 拷贝vector
	vector<int> v(lt2.begin(), lt2.end());

	// 排序
	sort(v.begin(), v.end());

	// 拷贝回lt2
	lt2.assign(v.begin(), v.end());

	int end1 = clock();

	int begin2 = clock();
	lt1.sort();
	int end2 = clock();

	printf("list copy vector sort copy list sort:%d\n", end1 - begin1);
	printf("list sort:%d\n", end2 - begin2);
}
int main()
{
	test_op1();
	test_op2();
	return 0;
}

其实list库中还有reverse(),但其实和算法中的reverse一样:(历史原因)

lt.reverse();
reverse(lt.begin(), lt.end());

splice也是list库中的接口,可以剪切自己或别人,将剪切的片段或元素添加到自己本身位置,它实现的是一种粘接,与复制粘贴不一样,他会影响对方,会夺取对方(从对方身上拔下来)

// 一个链表节点转移给另一个链表
std::list<int> mylist1, mylist2;
std::list<int>::iterator it;

// set some initial values:
for (int i = 1; i <= 4; ++i)
	mylist1.push_back(i);      // mylist1: 1 2 3 4

for (int i = 1; i <= 3; ++i)
	mylist2.push_back(i * 10);   // mylist2: 10 20 30

it = mylist1.begin();
++it;                         // points to 2

mylist1.splice(it, mylist2); 
// mylist1: 1 10 20 30 2 3 4
// mylist2 (empty)
// "it" still points to 2 (the 5th element

6.list的迭代器失效:

可将迭代器暂时理解成类似于指针, 迭代器失效即迭代器所指向的节点的无 效,即该节点被删除了 。因为 list 的底层结构为带头结点的双向循环链表 ,因此 list 中进行插入 时是不会导致 list 的迭代器失效的,只有在删除时才会失效,并且失效的只是指向被删除节点的迭 代器,其他迭代器不会受到影响:
list<int> lt;
lt.push_back(1);
lt.push_back(2);
lt.push_back(3);
lt.push_back(4);

// insert以后迭代器不失效
list<int>::iterator it = lt.begin();
lt.insert(it, 10);
*it += 100;

print_container(lt);

// erase以后迭代器失效
// 我们应该将erase后,保留迭代器
// 删除所有的偶数
it = lt.begin();
while (it != lt.end())
{
	if (*it % 2 == 0)
	{
		it = lt.erase(it);
	}
	++it;
}

print_container(lt);

7.list的底层的简单实现:

实现代码+测试代码:

#pragma once
#include<assert.h>

namespace home
{
	template<class T>
	struct list_node
	{
		T _data;
		list_node<T>* _next;
		list_node<T>* _prev;

		list_node(const T& data = T())
			:_data(data)
		    ,_next(nullptr)
			,_prev(nullptr)
		{}
	};


	封装
	//template<class T>
	//struct list_iterator
	//{
	//	typedef list_node<T> Node;
	//	typedef list_iterator<T> Self;
	//	Node* _node;
	//	list_iterator(Node* node)
	//		:_node(node)
	//	{}
	//	T& operator*()
	//	{
	//		return _node->_data
	//	}
	//	T* operator->()
	//	{
	//		//返回地址
	//		return &(_node->_data);
	//	}
	//	Self& operator++()
	//	{
	//		//我多写this->是为了方便理解
	//		this->_node = _node->_next;
	//		return *this;
	//	}
	//	Self operator++(T)
	//	{
	//		Self tmp(*this);
	//		_node = _node->_next;
	//		return tmp;
	//	}
	//	Self& operator--()
	//	{
	//		_node = _node->_prev;
	//		return *this;
	//	}
	//	Self operator--(T)
	//	{
	//		Self tmp(*this);
	//		_node = _node->_prev;
	//		return tmp;
	//	}
	//	bool operator!=(const Self& s)const
	//	{
	//		return _node != s._node;
	//	}
	//	bool operator==(const Self& s)const
	//	{
	//		return _node == s._node;
	//	}
	//};
	//template<class T>
	//struct list_const_iterator
	//{
	//	typedef list_node<T> Node;
	//	typedef list_const_iterator<T> Self;
	//	Node* _node;
	//	list_const_iterator(Node* node)
	//		:_node(node)
	//	{}
	//	const T& operator*()
	//	{
	//		return _node->_data;
	//	}
	//	const T* operator->()
	//	{
	//		//返回地址
	//		return &(_node->_data);
	//	}
	//	Self& operator++()
	//	{
	//		//我多写this->是为了方便理解
	//		this->_node = _node->_next;
	//		return *this;
	//	}
	//	Self operator++(T)
	//	{
	//		Self tmp(*this);
	//		_node = _node->_next;
	//		return tmp;
	//	}
	//	Self& operator--()
	//	{
	//		_node = _node->_prev;
	//		return *this;
	//	}
	//	Self operator--(T)
	//	{
	//		Self tmp(*this);
	//		_node = _node->_prev
	//		return tmp;
	//	}
	//	bool operator!=(const Self& s)const
	//	{
	//		return _node != s._node;
	//	}
	//	bool operator==(const Self& s)const
	//	{
	//		return _node == s._node;
	//	}
	//};
 


	//其实const_iteerator与iterator基本相似,可以用两个模板进行封装
    template<class T,class Ref,class Ptr>
	struct list_iterator
	{
		typedef list_node<T> Node;
		typedef list_iterator<T, Ref, Ptr> Self;
		Node* _node;
		list_iterator(Node* node)
			:_node(node)
		{}
		Ref operator*()
		{
			return _node->_data;
		}
		Ptr operator->()
		{
			return &(_node->_data);
		}
		Self& operator++()
		{
			this->_node = _node->_next;
			return *this;
		}
		Self operator++(int)
		{
			Self tmp(*this);
			_node = _node->_next;
			return tmp;
		}
		Self& operator--()
		{
			_node = _node->_next;
			return *this;
		}
		Self operator--(int)
		{
			Self tmp(*this);
			_node = _node->_next;
			return tmp;
		}
		bool operator!=(const Self& s)const
		{
			return _node != s._node;
		}
		bool operator==(const Self& s)const
		{
			return _node == s._node;
		}
	};


	template<class T>
	class list
	{
		typedef list_node<T> Node;
	public:
		/*typedef list_iterator<T> iterator;
		typedef list_const_iterator<T> const_iterator;*/
		
		//两个模板
		typedef list_iterator<T, T&, T*> iterator;
		typedef list_iterator<T, const T&, const T*> const_iterator;

		iterator begin()
		{
			//匿名+隐式类型转换
			return _head->_next;
		}
		
		iterator end()
		{
			return  _head;
		}

		const_iterator begin()const
		{
			return _head->_next;
		}

		const_iterator end()const
		{
			return _head;
		}

		//空初始化
		void empty_init()
		{
			_head = new Node;
			_head->_next = _head;
			_head->_prev = _head;
			_size = 0;
		}

		//默认构造
		list()
		{
			empty_init();
		}

		//{.....}初始化
		list(initializer_list<T> il)
		{
			empty_init();
			for (auto& e : il)
			{
				push_back(e);
			}
		}

		//拷贝构造
		list(const list<T>& lt)
		{
			empty_init();
			for (auto& e : lt)
			{
				push_back(e);
			}
		}

		//赋值拷贝
		list<T>& operator=(list<T> lt)
		{
			swap(lt);
			return *this;
		}

		~list()
		{
			clear();
			delete _head;
			_head = nullptr;
		}

		void clear()
		{
			auto it = begin();
			while (it != end())
			{
				it = erase(it);
			}
		}

		void swap(list<T> lt)
		{
			std::swap(_head, lt._head);
			std::swap(_size, lt._size);
		}

		void push_back(const T& x)
		{
			insert(end(), x);
		}
		void front_back(const T& x)
		{
			insert(begin(), x);
		}
	    iterator insert(iterator pos, const T& x)
		{
			Node* cur = pos._node;
			Node* prev = cur->_prev;
			Node* newnode = new Node(x);

			newnode->_prev = prev;
			prev->_next = newnode;
			newnode->_next = cur;
			cur->_prev = newnode;
			++_size;

			return newnode;
		}
		void pop_back()
		{
			erase(--end());
		}
		void pop_front()
		{
			erase(begin());
		}
		iterator erase(iterator pos)
		{
			assert(pos != end());//不可以删头节点
			Node* prev = pos._node->_prev;
			Node* next = pos._node->_next;

			prev->_next = next;
			prev->_prev = prev;
			delete pos._node;
			--_size;

			return next;
		}
		size_t size()const
		{
			return _size;
		}
		bool empty()const
		{
			return _size == 0;
		}
	private:
		Node* _head;
		size_t _size;
	};
	struct AA
	{
		int _a1 = 1;
		int _a2 = 1;
	};

	// 按需实例化
	// T* const ptr1
	// const T* ptr2
	template<class Container>
	void print_container(const Container& con)
	{
		// const iterator -> 迭代器本身不能修改
		// const_iterator -> 指向内容不能修改
		typename Container::const_iterator it = con.begin();
		//auto it = con.begin();
		while (it != con.end())
		{
			//*it += 10;

			cout << *it << " ";
			++it;
		}
		cout << endl;

		for (auto e : con)
		{
			cout << e << " ";
		}
		cout << endl;
	}
	void test_list1()
	{
		list<int> lt;
		lt.push_back(1);
		lt.push_back(2);
		lt.push_back(3);
		lt.push_back(4);

		list<int>::iterator it = lt.begin();
		while (it != lt.end())
		{
			*it += 10;

			cout << *it << " ";
			++it;
		}
		cout << endl;

		for (auto e : lt)
		{
			cout << e << " ";
		}
		cout << endl;
		print_container(lt);

		list<AA> lta;
		lta.push_back(AA());
		lta.push_back(AA());
		lta.push_back(AA());
		lta.push_back(AA());
		list<AA>::iterator ita = lta.begin();
		while (ita != lta.end())
		{
			//cout << (*ita)._a1 << ":" << (*ita)._a2 << endl;
			// 特殊处理,本来应该是两个->才合理,为了可读性,省略了一个->
			cout << ita->_a1 << ":" << ita->_a2 << endl;
			cout << ita.operator->()->_a1 << ":" << ita.operator->()->_a2 << endl;

			++ita;
		}
		cout << endl;
	}
	void test_list2()
	{
		list<int> lt;
		lt.push_back(1);
		lt.push_back(2);
		lt.push_back(3);
		lt.push_back(4);

		// insert以后迭代器不失效
		list<int>::iterator it = lt.begin();
		lt.insert(it, 10);
		*it += 100;

		print_container(lt);

		// erase以后迭代器失效
		// 删除所有的偶数
		it = lt.begin();
		while (it != lt.end())
		{
			if (*it % 2 == 0)
			{
				it = lt.erase(it);
			}
			it++;
		}

		print_container(lt);
	}

	void test_list3()
	{
		list<int> lt1;
		lt1.push_back(1);
		lt1.push_back(2);
		lt1.push_back(3);
		lt1.push_back(4);

		list<int> lt2(lt1);

		print_container(lt1);
		print_container(lt2);

		list<int> lt3;
		lt3.push_back(10);
		lt3.push_back(20);
		lt3.push_back(30);
		lt3.push_back(40);

		lt1 = lt3;
		print_container(lt1);
		print_container(lt3);
	}

	void func(const list<int>& lt)
	{
		print_container(lt);
	}

	void test_list4()
	{
		// 直接构造
		list<int> lt0({ 1,2,3,4,5,6 });
		// 隐式类型转换
		list<int> lt1 = { 1,2,3,4,5,6,7,8 };
		const list<int>& lt3 = { 1,2,3,4,5,6,7,8 };

		func(lt0);
		func({ 1,2,3,4,5,6 });

		print_container(lt1);

		//auto il = { 10, 20, 30 };
	/*	initializer_list<int> il = { 10, 20, 30 };
		cout << typeid(il).name() << endl;
		cout << sizeof(il) << endl;*/
	}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1989172.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

前端day7-css选择器

<!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0"><title>css</title><!-- 内嵌式CSS --><sty…

Python 为Excel单元格设置填充\背景色 (纯色、渐变、图案)

在使用Excel进行数据处理和分析时&#xff0c;对特定单元格进行背景颜色填充不仅能够提升工作表的视觉吸引力&#xff0c;还能帮助用户快速识别和区分不同类别的数据&#xff0c;增强数据的可读性和理解性。 本文将通过以下三个示例详细介绍如何使用Python在Excel中设置不同的单…

远程连接本地虚拟机失败问题汇总

前言 因为我的 Ubuntu 虚拟机是新装的&#xff0c;并且应该装的是比较纯净的版本&#xff08;纯净是指很多工具都尚未安装&#xff09;&#xff0c;然后在使用远程连接工具 XShell 连接时出现了很多问题&#xff0c;这些都是我之前没遇到过的&#xff08;因为之前主要使用云服…

javax.validation.constraints.NotEmpty 报错

1、问题 javax.validation.constraints.NotEmpty报错2、原因 validation-api版本较低问题 3、解决 升级版本 javax.validation:validation-api 由1.1.0.Final升级至 2.0.1.Final <dependency><groupId>javax.validation</groupId><artifactId>vali…

机房托管服务器说明

机房托管服务器是指将企业或个人的服务器放置到专业数据中心(IDC机房)进行管理和维护&#xff0c;由数据中心提供稳定、安全的运行环境以及网络连接等基础设施支持。rak小编为您整理发布机房托管服务器说明详细内容。 通过托管服务器到专业机房&#xff0c;企业能够享受到高性能…

【Redis 进阶】集群(重点理解流程和原理)

一、基本概念 前面学习的哨兵模式&#xff0c;提高了系统的可用性。但是真正用来存储数据的还是 master 和 slave 节点&#xff0c;所有的数据都需要存储在单个 master 和 slave 节点中。如果数据量很大&#xff0c;接近超出了 master / slave 所在机器的物理内存&#xff0c…

Maxon公司产品将于 2024 年 9 月提高订阅价格?

Maxon公司的用户们最近在Reddit和Core 4D论坛上分享了一张图片&#xff0c;图片内容显示了Maxon公司计划在2024年9月1日对其产品订阅价格进行调整&#xff0c;涉及的产品包括Cinema 4D和ZBrush等。 根据这张图片&#xff0c;Redshift渲染器的月度订阅费用将上涨2.2%&#xff0c…

社交网络的演变:从Facebook到Meta的战略转型

随着科技的飞速发展&#xff0c;社交网络平台正经历着深刻的变革。Facebook的品牌重塑为Meta不仅是名称的更改&#xff0c;更是对未来社交网络模式的全新定义。本文将深入探讨Facebook向Meta转型的背景、战略及其未来影响&#xff0c;剖析这一转型对社交网络的深远影响。 背景与…

UKP3d,AutoPDMS出报表时数值格式如何调整

用户问&#xff0c;支吊架一览表的位移数值不是整数&#xff0c;请问怎么处理呢&#xff1f; 1.在AutoPDMS是修改软件的安装目录下的配置文件&#xff0c;如图&#xff1a; 2.在UKP3d里修改报表元件&#xff0c;如图&#xff1a;

嵌入式day21

fileno 获得一个文件流指针中的文件描述符 FILE *fp -> int fd stream 文件流指针 返回值&#xff1a; 成功 返回文件描述符 失败 返回-1 关文件一般关封装度高的 fdopen 将文件描述符转化为文件流指针 int fd -> FILE *fp fd : 已经打开的文件描述符 mode &quo…

Unity检测鼠标进入、离开UI

Unity检测鼠标进入、离开UI检测 引用命名空间 UnityEngine.EventSystems IPointerEnterHandler&#xff1a;进入 IPointerExitHandler&#xff1a;离开 注意&#xff1a;Image需开启RaycastTarget using UnityEngine; using UnityEngine.EventSystems; public class IPointe…

8.7-主从数据库的配置+mysql的增删改查

一、mysql环境的配置 1.环境准备 &#xff08;1&#xff09;主数据库 #关闭防火墙 [rootmaster ~]# systemctl stop firewalld#关闭selinux [rootmaster ~]# setenforce 0#下载lrzsz工具 [rootmaster ~]# yum -y install lrzsz#安装rsync [rootmaster ~]# yum -y install rs…

如何高效利用阿里云Docker镜像仓库管理您的容器镜像

文章目录 前言一、Docker镜像仓库1.公共仓库2.私有仓库 二、开通阿里云Docker镜像仓库ACR1.创建阿里云账号并开通容器镜像服务2.创建命名空间与镜像仓库 三、如何使用镜像仓库ACR1.登录阿里云Docker Registry2.推送镜像到阿里云私有镜像仓库3.从阿里云私有镜像仓库拉取镜像 总结…

CAN直接网络管理(20240805)

长安CAN网络管理规范 个人理解&#xff1a;管理CAN网络中各NM节点的工作模式&#xff08;状态&#xff09;&#xff1b; 1.术语定义 &#x1f449;节点地址&#xff1a;用于唯一标识网络中每个节点的单字节数字&#xff0c;取值范围是 0x00~0xFF。&#x1f449;状态迁移&#x…

Vue3从零开始——掌握setup、ref和reactive函数的奥秘

文章目录 一、Vue 3 组合式 API 概述二、setup​ 函数的基本使用2.1 setup​ 函数的特点2.2 setup​ 函数的基本结构2.3 实现一个简单的小demo 三、ref​ 函数的功能和应用3.1 ref​函数介绍3.2 基本使用3.2.1 定义ref​数据3.2.2 修改响应式变量 3.3 使用ref​函数实现计数器 …

CTFHUB-web-RCE-过滤空格

开启题目 在 URL 后面拼接使用管道符执行注入&#xff0c;发现了 flag 的可疑文件 127.0.0.1|ls 因为这题过滤了空格&#xff0c;如果在 URL 中输入空格&#xff0c;则不会执行 ping 命令。那么这里将空格替换为 %09 &#xff0c;也就是 ASCII 的 Tab 键。右键检查网页源代码发…

【OpenCV-Python实战项目】01-OCR文本检测

OpenCVTesseract文本检测 0.介绍1.基础功能实现1.1 字符检测1.2 单词检测1.3 只检测数字 2.工程应用2.1 封装类2.2 屏幕截图识别2.3 视频文本检测&#xff08;待优化&#xff09; 3.参考 0.介绍 &#xff08;1&#xff09;Tesseract是一个开源文本识别 (OCR)引擎&#xff0c;是…

TypeScript数组

数组 数组 数据存储的集合 声明数组的两种方式 1.只声明不赋值 &#xff1a;let arr1:string[] <>泛型 数组在使用前先赋值 2.边声明边赋值 let arr3:string[][];//空数组 // [数据1,数据2,.....数据n]数据之间用,隔开 let arr4:string[][张三,李四,王五]; let ar…

A. Array

https://codeforces.com/gym/102875/problem/A p<30 可以建立30颗线段树维护 然后看操作 一.add 懒标记 二.mul 三.mi 好像不能找到 于是懒标记貌似不能做&#xff0c; 但是考虑结果都要mod p,所以数都在0-p之间 其实就是i-> (操作)%p的映射 那就不用维护别的标…

MySQL —— 约束

MySQL —— 约束 引言not nulluniqueprimary key —— 主键auto_increment复合主键 foreign key —— 外键插入数据删除主表的数据 default 引言 在设计表的时候&#xff0c;有些列是必填项&#xff08;如果用户不填&#xff0c;那这个数据就没有必要存进数据库&#xff09;&a…