C++—vector的使用及实现

news2024/10/1 8:28:07

✨✨ 欢迎大家来到小伞的大讲堂✨✨

🎈🎈养成好习惯,先赞后看哦~🎈🎈

所属专栏:C++学习
小伞的主页:xiaosan_blog

1.vector

1.1vector的介绍

cplusplus.com/reference/vector/vector/

1.2vector的使用

(constructor)构造函数声明接口说明

vector()(重点)无参构造

vector(size_type n, const value_type& val =value_type())构造并初始化n个val

vector (const vector& x); (重点)拷贝构造

vector (InputIterator first, InputIterator last);使用迭代器进行初始化构造

int  test_vector()
{
	
	//vectoe
	vector<int>s1;
	vector<int>s2(4, 100);//长度为4,值为100的数组
	vector<int>s3(s2.begin(), s2.end());
	vector<int>s4(s2);//拷贝构造

	int myints[] = { 16,2,77,29 };
	vector<int> fifth(myints, myints + sizeof(myints) / sizeof(int));//与s3类似
	//迭代器
	cout << "The contents of fifth are:";
	for (vector<int>::iterator it = fifth.begin(); it != fifth.end(); ++it)
		cout << ' ' << *it;
	cout << '\n';

	return 0;
}

void PrintVector(const vector<int>& v)
{
	// const对象使用const迭代器进行遍历打印
	vector<int>::const_iterator it = v.begin();
	while (it != v.end()) {
		cout << *it << endl;
		it++;
	}
}

1.2 vector iterator 的使用

iterator的使用接口说明

begin +end(重点)获取第一个数据位置的iterator/const_iterator, 获取最后一个数据的下一个位置的iterator/const_iterator

rbegin +rend获取最后一个数据位置的reverse_iterator,获取第一个数据前一个位置的reverse_iterator

 注意:rbegin +rend(反向迭代器)指向最后一个数据,每次++,获取前一个位置

void TestVector2()
{
	vector<int> v;
	v.push_back(1);
	v.push_back(2);
	v.push_back(3);
	v.push_back(4);

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

	// 使用迭代器进行修改
	it = v.begin();
	while (it != v.end())
	{
		*it *= 2;
		++it;
	}
	// 使用反向迭代器进行遍历再打印
	// vector<int>::reverse_iterator rit = v.rbegin();
	auto rit = v.rbegin();//反向迭代器,每次++,往头部走
	while (rit != v.rend())
	{
		cout << *rit << " ";
		++rit;
	}
	cout << endl;

	PrintVector(v);
}

1.3 vector 空间增长问题 

容量空间接口说明

size获取数据个数

capacity获取容量大小

empty判断是否为空

resize(重点)改变vector的size

reserve (重点)改变vector的capacity

1.capacity的代码在vs和g++下分别运行会发现,vs下capacity是按1.5倍增长的,g++是按2倍增长的。这个问题经常会考察,不要固化的认为,vector增容都是2倍,具体增长多少是根据具体的需求定义的。vs是PJ版本STL,g++是SGI版本STL。

2.reserve只负责开辟空间,如果确定知道需要用多少空间,reserve可以缓解vector增容的代价缺陷问题。

3.resize在开空间的同时还会进行初始化,影响size。

//  vector的resize 和 reserve

// reisze(size_t n, const T& data = T())
// 将有效元素个数设置为n个,如果时增多时,增多的元素使用data进行填充
// 注意:resize在增多元素个数时可能会扩容
void TestVector3()
{
	vector<int> v;

	for (int i = 1; i < 10; i++)
	v.push_back(i);
	v.resize(5);//会删除多余的元素
	v.resize(8, 100);//有元素的位置不会改变,空间不够时,会开辟空间,值为100
	v.resize(12);//开空间值为0;

	cout << "v contains:";
	for (size_t i = 0; i < v.size(); i++)
		cout << ' ' << v[i];
	cout << '\n';
}

// 测试vector的默认扩容机制
// vs:按照1.5倍方式扩容   // linux:按照2倍方式扩容
void TestVectorExpand()
{
	size_t sz;
	vector<int> v;
	sz = v.capacity();
	cout << "making v grow:\n";
	for (int i = 0; i < 100; ++i)
	{
		v.push_back(i);
		if (sz != v.capacity())
		{
			sz = v.capacity();
			cout << "capacity changed: " << sz << '\n';
		}
	}
}// vs: 1 2 3 4 6 9 13 19 28 42 63 94 141    

// 往vecotr中插入元素时,如果大概已经知道要存放多少个元素
// 可以通过reserve方法提前将容量设置好,避免边插入边扩容效率低
void TestVectorExpandOP()
{
	vector<int> v;
	size_t sz = v.capacity();
	v.reserve(100);   // 提前将容量设置好,可以避免一遍插入一遍扩容
	cout << "making bar grow:\n";
	for (int i = 0; i < 100; ++i)
	{
		v.push_back(i);
		if (sz != v.capacity())
		{
			sz = v.capacity();
			cout << "capacity changed: " << sz << '\n';
		}
	}
}

 1.4 vector 增删查改

vector增删查改接口说明

push_back(重点)尾插

pop_back (重点)尾删

find查找。(注意这个是算法模块实现,不是vector的成员接口)

insert在position之前插入val

erase删除position位置的数据

swap交换两个vector的数据空间

operator[] (重点)像数组一样访问

//  vector的增删改查
// 尾插和尾删:push_back/pop_back
void TestVector4()
{
	vector<int> v;
	v.push_back(1);
	v.push_back(2);
	v.push_back(3);
	v.push_back(4);
    
	auto it = v.begin();
	while (it != v.end())
	{
		cout << *it << " ";
		++it;
	}
	cout << endl;

	v.pop_back();
	v.pop_back();

	it = v.begin();
	while (it != v.end())
	{
		cout << *it << " ";
		++it;
	}
	cout << endl;
}

// 任意位置插入:insert和erase,以及查找find
// 注意find不是vector自身提供的方法,是STL提供的算法
void TestVector5()
{
	// 使用列表方式初始化,C++11新语法
	vector<int> v{ 1, 2, 3, 4 };

	// 在指定位置前插入值为val的元素,比如:3之前插入30,如果没有则不插入
	// 1. 先使用find查找3所在位置
	// 注意:vector没有提供find方法,如果要查找只能使用STL提供的全局find
	auto pos = find(v.begin(), v.end(), 3);
	if (pos != v.end())
	{
		// 2. 在pos位置之前插入30
		v.insert(pos, 30);
	}

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

	pos = find(v.begin(), v.end(), 3);
	// 删除pos位置的数据
	v.erase(pos);

	it = v.begin();
	while (it != v.end()) {
		cout << *it << " ";
		++it;
	}
	cout << endl;
}
// operator[]+index 和 C++11中vector的新式for+auto的遍历
// vector使用这两种遍历方式是比较便捷的。
void TestVector6()
{
	vector<int> v{ 1, 2, 3, 4 };

	// 通过[]读写第0个位置。
	v[0] = 10;
	cout << v[0] << endl;

	// 1. 使用for+[]小标方式遍历
	for (size_t i = 0; i < v.size(); ++i)
		cout << v[i] << " ";
	cout << endl;

	vector<int> swapv;
	swapv.swap(v);//交换数据

	cout << "v data:";
	for (size_t i = 0; i < v.size(); ++i)
		cout << v[i] << " ";
	cout << endl;

	// 2. 使用迭代器遍历
	cout << "swapv data:";
	auto it = swapv.begin();
	while (it != swapv.end())
	{
		cout << *it << " ";
		++it;
	}

	// 3. 使用范围for遍历
	for (auto x : v)
		cout << x << " ";
	cout << endl;
}

1.5 vector 迭代器失效问题。

迭代器的主要作用就是让算法能够不用关心底层数据结构,其底层实际就是一个指针或者是对指针进行了封装,比如:vector的迭代器就是原生态指针T* 。因此迭代器失效,实际就是迭代器底层对应指针所指向的空间被销毁了,而使用一块已经被释放的空间,造成的后果是程序崩溃(即如果继续使用已经失效的迭代器,程序可能会崩溃)。

对于vector可能会导致其迭代器失效的操作有:

1.5.1 会引起其底层空间改变的操作

1. 会引起其底层空间改变的操作,都有可能是迭代器失效,比如:resize、reserve、insert、

assign、push_back等。

  •  reserve的作用就是改变扩容大小但不改变有效元素个数,操作期间可能会引起底层容量改变
  • 插入元素期间,可能会引起扩容,而导致原空间被释放
  • vector重新赋值,可能会引起底层容量改变

为了防止这样的状况,通常会在后续使用前重新赋值it 

int main()
{
vector<int> v{1,2,3,4,5,6};
auto it = v.begin();
// 将有效元素个数增加到100个,多出的位置使用8填充,操作期间底层会扩容
// v.resize(100, 8);
// reserve的作用就是改变扩容大小但不改变有效元素个数,操作期间可能会引起底层容
量改变
// v.reserve(100);
// 插入元素期间,可能会引起扩容,而导致原空间被释放
// v.insert(v.begin(), 0);
// v.push_back(8);
// 给vector重新赋值,可能会引起底层容量改变
v.assign(100, 8);
/*
出错原因:以上操作,都有可能会导致vector扩容,也就是说vector底层原理旧空间被释
放掉,而在打印时,it还使用的是释放之间的旧空间,在对it迭代器操作时,实际操作的是一块
已经被释放的空间,而引起代码运行时崩溃。
解决方式:在以上操作完成之后,如果想要继续通过迭代器操作vector中的元素,只需给
it重新赋值即可。
*/
while(it != v.end())
{
cout<< *it << " " ;
++it;
} c
out<<endl;
return 0;
}

1.5.2 指定位置元素的删除操作--erase

#include<iostream>

using namespace std;
#include <vector>
int main()
{
int a[] = { 1, 2, 3, 4 };
vector<int> v(a, a + sizeof(a) / sizeof(int));
// 使用find查找3所在位置的iterator
vector<int>::iterator pos = find(v.begin(), v.end(), 3);
// 删除pos位置的数据,导致pos迭代器失效。
v.erase(pos);
cout << *pos << endl; // 此处会导致非法访问
return 0;
}

erase删除pos位置元素后,pos位置之后的元素会往前搬移,没有导致底层空间的改变,理论上讲迭代器不应该会失效,但是如果pos刚好是最后一个元素,删完之后pos刚好是end的位置,而end位置是没有元素的,那么pos就失效了。因此删除vector中任意位置上元素时,vs就认为该位置迭代器失效了

1.5.3 与vector类似,string在插入+扩容操作+erase之后,迭代器也会失效
 

#include <string>
void TestString()
{
string s("hello");
auto it = s.begin();
// 放开之后代码会崩溃,因为resize到20会string会进行扩容
// 扩容之后,it指向之前旧空间已经被释放了,该迭代器就失效了
// 后序打印时,再访问it指向的空间程序就会崩溃
//s.resize(20, '!');
while (it != s.end())
{
cout << *it;
++it;
} c
out << endl;
it = s.begin();
while (it != s.end())
{
it = s.erase(it);
// 按照下面方式写,运行时程序会崩溃,因为erase(it)之后
// it位置的迭代器就失效了
// s.erase(it);
++it;
}
}

迭代器失效解决办法:在使用前,对迭代器重新赋值即可

2.vector的模拟实现

2.1 vector.h

#include<iostream>
#include<assert.h>
#include<vector>
using namespace std;

namespace sui {
	template<class T>
	class vector
	{
	public:
		typedef T* iterator;
		typedef const T* iterator_const;

		iterator begin();

		iterator end();

		iterator_const cbegin();

		iterator_const cned() const;

		vector();

		void reserve(size_t n);

		size_t size()const;

		size_t capacity()const;

		bool empty();

		void push_back(const T& X);

		void clear();

		void pop_back();

		void swap(vector<T>& v);

		~vector();

		T& operator[](size_t pos);

		const T& operator[](size_t pos) const ;

		iterator insert(iterator pos, const T& x);

	private:
		iterator _start = nullptr;
		iterator _finish = nullptr;
		iterator _end_of_storage = nullptr;
	};
};

2.1.1 Init(初始化)

vector() {
	_start = nullptr;
	iterator _finish = nullptr;
	iterator _end_of_storage = nullptr;
}

private:
	iterator _start = nullptr;
	iterator _finish = nullptr;
	iterator _end_of_storage = nullptr;

我们可以通过初始化函数或者在成员中初始化

2.1.2 reserve

 因为开辟空间会导致原有空间的摧毁,导致存放size的数据丢失,所以创建old_size保存size的值

void reserve(size_t n) {
	if (n > capacity()) {

		size_t old_size = size();
		T* tmp = new T[n];
		//从某个数组,_start位置,复制sizeof(T)个字节
		memcpy(tmp, _start, size() * sizeof(T));
		delete[] _start;//会导致原size丢失,所以先保存原本的size,然后赋值

		_start = tmp;
		_finish = tmp + old_size;
		_end_of_storage = tmp + n;
	}
}

2.1.3 size和capacity(指针相减)

size_t size()const {
	return _finish - _start;
}
size_t capacity()const {
	return _end_of_storage - _start;
}

2.1.4 empty

bool empty() {
	return _start == _finish;
}

2.1.5 push_back()

void push_back(const T& X) {
	if (_finish == capacity) {
		reserve(capacity() == 0 ? 4 : capacity() * 2);
	}
	*_finish = X;
	++_finish;
}

2.1.6 clear()

void clear()
{
	_finish = _start;
}

2.1.7 pop_back()

void pop_back() {
	assert(! empty());
	_finish--;
}

2.1.8 swap

利用库中的swap函数 

void swap(vector<T>& v)
{
	std::swap(_start, v._start);
	std::swap(_finish, v._finish);
	std::swap(_end_of_storage, v._end_of_storage);
}

2.1.9 ~析构

需要判断是否为NULL. 

~vector() {
	//判断是否为NULL;
	if (_start)
	{
		delete[] _start;
		_start = _finish = _end_of_storage = nullptr;
	}
}

2.1.10 []下标访问

T& operator[](size_t pos)
{
	assert(pos < size());
	return _start[pos];
}

const T& operator[](size_t pos) const {
	assert(pos < size());
	return _start[pos];
}

2.1.11 insert(目标位置插入)

需要向后插入 

iterator insert(iterator pos, const T& x)
{
	// 扩容
	if (_finish == _end_of_storage)
	{
		size_t len = pos - _start;
		reserve(capacity() == 0 ? 4 : capacity() * 2);
		pos = _start + len;
	}

	iterator end = _finish - 1;
	while (end >= pos)
	{
		*(end + 1) = *end;
		--end;
	}
	*pos = x;

	++_finish;

	return pos;
}

2.1.12 begin+end

iterator begin() {
	return _start;
}
iterator end() {
	return _finish;
}
iterator_const cbegin() 
{
	return _start;
}
iterator_const cned() const 
{
	return _finish;
}

2.2 vector模拟实现的整体代码

#pragma once

#include<iostream>
#include<assert.h>
#include<vector>
using namespace std;

namespace sui {
	template<class T>
	class vector
	{
	public:
		typedef T* iterator;
		typedef const T* iterator_const;

		iterator begin() {
			return _start;
		}
		iterator end() {
			return _finish;
		}
		iterator_const cbegin() 
		{
			return _start;
		}
		iterator_const cned() const 
		{
			return _finish;
		}
		vector() {
			_start = nullptr;
			iterator _finish = nullptr;
			iterator _end_of_storage = nullptr;
		}

		void reserve(size_t n) {
			if (n > capacity()) {

				size_t old_size = size();
				T* tmp = new T[n];
				//从某个数组,_start位置,复制sizeof(T)个字节
				memcpy(tmp, _start, size() * sizeof(T));
				delete[] _start;//会导致原size丢失,所以先保存原本的size,然后赋值

				_start = tmp;
				_finish = tmp + old_size;
				_end_of_storage = tmp + n;
			}
		}

		size_t size()const {
			return _finish - _start;
		}
		size_t capacity()const {
			return _end_of_storage - _start;
		}

		bool empty() {
			return _start == _finish;
		}

		void push_back(const T& X) {
			if (_finish == capacity) {
				reserve(capacity() == 0 ? 4 : capacity() * 2);
			}
			*_finish = X;
			++_finish;
		}

		void clear()
		{
			_finish = _start;
		}

		void pop_back() {
			assert(! empty());
			_finish--;
		}

			void swap(vector<T>& v)
			{
				std::swap(_start, v._start);
				std::swap(_finish, v._finish);
				std::swap(_end_of_storage, v._end_of_storage);
			}

		~vector() {
			//判断是否为NULL;
			if (_start)
			{
				delete[] _start;
				_start = _finish = _end_of_storage = nullptr;
			}
		}

		T& operator[](size_t pos)
		{
			assert(pos < size());
			return _start[pos];
		}

		const T& operator[](size_t pos) const {
			assert(pos < size());
			return _start[pos];
		}


		iterator insert(iterator pos, const T& x)
		{
			// 扩容
			if (_finish == _end_of_storage)
			{
				size_t len = pos - _start;
				reserve(capacity() == 0 ? 4 : capacity() * 2);
				pos = _start + len;
			}

			iterator end = _finish - 1;
			while (end >= pos)
			{
				*(end + 1) = *end;
				--end;
			}
			*pos = x;

			++_finish;

			return pos;
		}

	private:
		iterator _start = nullptr;
		iterator _finish = nullptr;
		iterator _end_of_storage = nullptr;
	};
};

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

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

相关文章

wpa_cli支持EAP-TTLS认证运行设计

wpa_cli支持EAP-TTLS认证运行设计 1 输入 1.1 启动wpa_supplicant 和 wpa_cli 在OpenHarmony开发板或华为开发机的命令行中输入 wpa_supplicant -Dnl80211 -c/data/service/el1/public/wifi/wpa_supplicant/wpa_supplicant.conf -gabstract:/data/service/el1/public/wifi/s…

【D3.js in Action 3 精译_026】3.4 小节 DIY 实战:基于 Mocha 在浏览器客户端测试 D3 线性比例尺

当前内容所在位置&#xff08;可进入专栏查看其他译好的章节内容&#xff09; 第一部分 D3.js 基础知识 第一章 D3.js 简介&#xff08;已完结&#xff09; 1.1 何为 D3.js&#xff1f;1.2 D3 生态系统——入门须知1.3 数据可视化最佳实践&#xff08;上&#xff09;1.3 数据可…

力扣(leetcode)每日一题 2286 以组为单位订音乐会的门票 | 线段树

2286. 以组为单位订音乐会的门票 题干 一个音乐会总共有 n 排座位&#xff0c;编号从 0 到 n - 1 &#xff0c;每一排有 m 个座椅&#xff0c;编号为 0 到 m - 1 。你需要设计一个买票系统&#xff0c;针对以下情况进行座位安排&#xff1a; 同一组的 k 位观众坐在 同一排座…

物联网实训室建设的必要性

物联网实训室建设的必要性 一、物联网发展的背景 物联网&#xff08;IoT&#xff09;是指通过信息传感设备&#xff0c;按照约定的协议&#xff0c;将任何物品与互联网连接起来&#xff0c;进行信息交换和通信&#xff0c;以实现智能化识别、定位、跟踪、监控和管理的一种网络…

c语言实例 068

大家好&#xff0c;欢迎来到无限大的频道 今天给大家带来的是c语言。 题目描述 创建一个单链表&#xff0c;进行存储数据并且打印 创建一个单链表的基本步骤包括定义链表节点的结构体、实现插入数据的功能&#xff0c;以及打印链表的内容。以下是一个简单的C语言示例&#…

QT将QBytearray的data()指针赋值给结构体指针变量后数据不正确的问题

1、问题代码 #include <QCoreApplication>#pragma pack(push, 1) typedef struct {int a; // 4字节float b; // 4字节char c; // 1字节int *d; // 8字节 }testStruct; #pragma pack(pop)#include <QByteArray> #include <QDebug>int main() {testStruct …

【C++前缀和 数论 贪心】2245. 转角路径的乘积中最多能有几个尾随零|2036

本文涉及的基础知识点 C算法&#xff1a;前缀和、前缀乘积、前缀异或的原理、源码及测试用例 包括课程视频 质数、最大公约数、菲蜀定理 贪心&#xff08;决策包容性) LeetCode2245. 转角路径的乘积中最多能有几个尾随零 给你一个二维整数数组 grid &#xff0c;大小为 m x …

【有啥问啥】二分图(Bipartite Graph)算法原理详解

二分图&#xff08;Bipartite Graph&#xff09;算法原理详解 引言 二分图&#xff08;Bipartite Graph&#xff09;&#xff0c;又称二部图&#xff0c;是图论中的一个重要概念。在实际应用中&#xff0c;二分图模型经常用于解决如匹配问题、覆盖问题和独立集问题等。本文将…

实验2思科网院项目2.7.2-packet-tracer---configure-single-area-ospfv2---实践练习

实践练习 2.7.2-packet-tracer---configure-single-area-ospfv2---实践练习physical-mode 实验拓扑 相关设备配置 实验目标: 第 1 部分&#xff1a;构建网络并配置设备的基本设置 第 2 部分&#xff1a;配置和验证单区域 OSPFv2 的基本部署 第 3 部分&#xff1a;优化和验…

【STM32】 TCP/IP通信协议(3)--LwIP网络接口

LwIP协议栈支持多种不同的网络接口&#xff08;网卡&#xff09;&#xff0c;由于网卡是直接跟硬件平台打交道&#xff0c;硬件不同则处理也是不同。那Iwip如何兼容这些不同的网卡呢&#xff1f; LwIP提供统一的接口&#xff0c;底层函数需要用户自行完成&#xff0c;例如网卡的…

动态时钟控件:Qt/C++ 项目代码解读

基于Qt的动态时钟控件项目。该项目展示了如何通过Qt的绘图系统绘制一个带有表盘背景、时针、分针、秒针、以及时间日期显示的时钟。同时&#xff0c;这个时钟控件支持背景切换&#xff0c;并且每秒钟刷新一次&#xff0c;实时显示当前时间。 项目结构与功能概述 该时钟控件主…

Redis接口访问优化

说明&#xff1a;之前写过一篇使用Redis接口访问的博客&#xff0c;如下。最近有相关需求&#xff0c;把代码拿出来后&#xff0c;做了一些优化&#xff0c;挺有意思的&#xff0c;本文介绍在原基础上 使用Redis实现接口防抖 优化 总的来说&#xff0c;这次使用Redis实现接口…

自动驾驶汽车横向控制方法研究综述

【摘要】 为实现精确、稳定的横向控制&#xff0c;提高车辆自主行驶的安全性和保障乘坐舒适性&#xff0c;综述了近年来自动驾驶汽车横向控制方法的最新进展&#xff0c;包括经典控制方法和基于深度学习的方法&#xff0c;讨论了各类方法的性能特点及在应用中的优缺点&#xff…

【初阶数据结构】详解插入排序 希尔排序(内含排序的概念和意义)

文章目录 前言1. 排序的概念及其应用1.1 排序的概念1.2 排序的应用 2. 插入排序2.1 基本思想2.2 插入排序的代码实现2.3 插入排序算法总结 3. 希尔排序3.1 基本思想3.2 希尔排序的代码实现3.3 希尔排序的特征总结 前言 初级数据结构系列已经进入到了排序的部分了。相信大家听到…

计算机毕业设计 服装生产信息管理系统的设计与实现 Java实战项目 附源码+文档+视频讲解

博主介绍&#xff1a;✌从事软件开发10年之余&#xff0c;专注于Java技术领域、Python人工智能及数据挖掘、小程序项目开发和Android项目开发等。CSDN、掘金、华为云、InfoQ、阿里云等平台优质作者✌ &#x1f345;文末获取源码联系&#x1f345; &#x1f447;&#x1f3fb; 精…

记录|Modbus-TCP产品使用记录【德克威尔】

目录 前言一、德克威尔1.1 实验图1.2 DECOWELL IO Tester 软件1.3 读写设置1.4 C#进行Modbus-TCP读写 更新时间 前言 参考文章&#xff1a; 使用的第二款Modbus-TCP产品。 一、德克威尔 1.1 实验图 1.2 DECOWELL IO Tester 软件 这也是自带模块配置软件的。下图就是德克威尔的…

“Xian”(籼)和“Geng”(粳)米怎么读?

2018年&#xff0c;《自然》上刊登了一篇有关亚洲栽培稻基因组变异的重磅论文。研究成果本身自然引人关注&#xff0c;但更引人关注的是&#xff0c;这篇论文首次提出以“Xian”&#xff08;籼&#xff09;和“Geng”&#xff08;粳&#xff09;两个汉语农业术语代替Indica和Ja…

yum使用阿里云的镜像源报错 Failed connect to mirrors.aliyuncs.com:80; Connection refused“

报错&#xff1a;Failed connect to mirrors.aliyuncs.com:80; Connection refused"&#xff0c;如果单独只是这个报错的话&#xff0c;那么原因是由于非阿里云ECS用户无法解析主机“mirrors.cloud.aliyuncs.com”。如果不单单只是这个报错另外还有其它报错请参考我其它文…

Threejs创建正多边体

上一章节实现了球体的绘制&#xff0c;这节来绘制多面体&#xff0c;包括正多面体&#xff0c;平面中&#xff0c;每条边一样长组成的图形叫正多边形&#xff0c;这里每个面一样&#xff0c;叫正多面体。如上文一样&#xff0c;先要创建出基础的组件&#xff0c;包括场景&#…

C++基础---类和对象(上)

1.类的定义 C程序设计允许程序员使用类&#xff08;class&#xff09;定义特定程序中的数据类型。这些数据类型的实例被称为对象 &#xff0c;这些实例可以包含程序员定义的成员变量、常量、成员函数&#xff0c;以及重载的运算符。语法上&#xff0c;类似C中结构体&#xff0…