0902,DEQUE,LIST,VECTOR

news/2024/9/17 7:49:51/ 标签: list, 数据结构, c++

目录

01_vector.cc

02_vector.cc

作业

01STL包括哪些组件?各自具有哪些特点?

02 序列式容器包括哪些?他们之间有哪些异同?

03 下面程序有什么错误?

list%E5%86%99%E5%87%BA%E6%9D%A5-toc" style="margin-left:80px;">04 创建和初始化vector的方法,每种都给出一个实例?当然也可以把deque与list写出来

05 如果c1与c2是两个容器,下面的比较操作有什么限制?if(c1 < c2)

06 STL中的std::deque容器的实现原理?

07 评委打分的例子:要求:有五名选手ABCDE,10个评委打分,去掉最高分和最低分,求出每个选手的平均分。

08 编程题:从一个 vector 初始化一个 string。

09 题目:使用vector打印九九乘法表。

01_vector.cc

#include <iostream>
#include <vector>
using std::cout;
using std::endl;
using std::vector;template <class T>
class vec{
public:
private:typedef T* _iterator;
};
void test(){/*1*/vector<int> num0;/*2*/vector<int> num1(10,5);//count same valueint arr[10]={0,1,2,3,4,5,6,7,8,9};/*3*/vector<int> num2(arr,arr+10);//[0,10)/*4*///copy & move/*5*/vector<int> num3{4,5,6,3,2,7,3,9};//-----------------------------------//vector<int>::iterator it=num1.begin();//未初始化迭代器for(;it!=num1.end();++it){cout<<*it<<" ";}cout<<endl;//-----------------------------------//for(size_t idx;idx!=sizeof(arr)/sizeof(arr[0]);++idx){cout<<num1[idx]<<" ";}cout<<endl;//-----------------------------------//for(auto itt=num2.begin();itt!=num2.end();itt++){cout<<*itt<<" ";}cout<<endl;//-----------------------------------//for(auto &ele: num3){cout<<ele<<" ";}cout<<endl;
}int main(void)
{test();return 0;
}

02_vector.cc

#include <iostream>
#include <vector>
#include <deque>
#include <list>
using std::cout;
using std::endl;
using std::vector;
using std::list;
using std::deque;template <typename Container>
void display(const Container & con){for(auto &ele: con){cout<<ele<<" ";}cout<<endl;
}
void display_cap(const vector<int> & con){cout<<endl;display(con);cout<<"size::"<<con.size()<<endl;cout<<"capacity::"<<con.capacity()<<endl;
}//---------------------------------//
//vector  可变数组
template <class T>
class vec{
public:T* data(){return _M_start;}
private:T* _M_start;           //第一个元素T* _M_finish;          //最后一个元素的下一个位置T* _M_end_of_storage;  //最后一个空间的下一个位置
};
//---------------------------------//
//deque  逻辑连续 物理存储分散
//中控器数组 Map  -->  小片段(内部连续)
//迭代器不是一个普通类型的指针,是一个类,对指针的基本功能都做了重载
template <class T>
class _Tp{
private:_Tp* _M_cur;_Tp* _M_first;_Tp* _M_last;/* _Map_pointer _M_node;  //和中控器联系 */
};
template <class _Tp,class _Alloc>
class _deque_base{
};
//---------------------------------//void test(){vector<int> num3{4,5,6,7,8,9};display(num3);num3.push_back(333);display(num3);num3.pop_back();display(num3);//vector不支持头部插入和删除,一端开口//效率——整体前移/后移cout<<"<<<<<<<<<<<<<<<<vector first number addr"<<endl;&num3;//error  _M_tartcout<<&(*num3.begin())<<endl;cout<<&(num3[0])<<endl;int *pdata=num3.data();cout<<pdata<<endl;vector<int>::iterator v_it=num3.begin();v_it++;v_it+=2;cout<<"*v_it  "<<*v_it<<endl;num3.insert(v_it,11);//insert front ,return curdisplay_cap(num3);cout<<"*v_it  "<<*v_it<<endl;/* num3.insert(v_it,10,222);//迭代器失效 invalid pointer */v_it=num3.begin();num3.insert(v_it,10,222);//迭代器失效 invalid pointerdisplay_cap(num3);cout<<"*v_it  "<<*v_it<<endl;v_it=num3.begin();num3.insert(v_it,{666,777,888});display_cap(num3);cout<<"*v_it  "<<*v_it<<endl;v_it=num3.begin();num3.insert(v_it,num3.begin(),num3.end());display_cap(num3);cout<<"*v_it  "<<*v_it<<endl;//insert操作的时候,会导致底层发生扩容操作//迭代器还指向老的空间,老的空间已经回收了,所以//迭代器失效了//解决:每次都重新 置位 迭代器cout<<endl<<endl;//-----------------------------//list<int> num2{4,5,6,7,8,9};display(num2);num2.push_back(333);num2.push_front(44444);display(num2);num2.pop_back();num2.pop_front();display(num2);cout<<"<<<<<<<<<<<<<<<<<<list push anywhere"<<endl;list<int>::iterator l_it=num2.begin();l_it++;/* l_it+=2; */cout<<"*l_it  "<<*l_it<<endl;num2.insert(l_it,11);//insert front ,return curdisplay(num2);cout<<"*l_it  "<<*l_it<<endl;num2.insert(l_it,3,222);display(num2);cout<<"*l_it  "<<*l_it<<endl;num2.insert(l_it,{666,777,888});display(num2);cout<<"*l_it  "<<*l_it<<endl;num2.insert(l_it,num2.begin(),num2.end());display(num2);cout<<"*l_it  "<<*l_it<<endl;cout<<endl<<endl;//-----------------------------//deque<int> num1{0,1,2,3,4,5,6,7};display(num1);num1.push_back(333);num1.push_front(44444);display(num1);num1.pop_back();num1.pop_front();display(num1);cout<<"<<<<<<<<<<<<<<<<<<deque push anywhere"<<endl;deque<int>::iterator d_it=num1.begin();d_it++;d_it+=2;cout<<"*d_it  "<<*d_it<<endl;num1.insert(d_it,11);//insert前面一半,前移前面一半,后面一半后移display(num1);cout<<"*d_it  "<<*d_it<<endl;num1.insert(d_it,3,222);display(num1);cout<<"*d_it  "<<*d_it<<endl;num1.insert(d_it,{666,777,888});display(num1);cout<<"*d_it  "<<*d_it<<endl;num1.insert(d_it,num1.begin(),num1.end());display(num1);cout<<"*d_it  "<<*d_it<<endl;cout<<endl;}int main(void)
{test();return 0;
}

作业

01STL包括哪些组件?各自具有哪些特点?

01 容器(用来存放数据,也是数据结构
02 算法(用来实现容器的算法操作
03 迭代器(用来访问容器中的成员,是广义上的指针,也叫泛型指针
04 适配器(起到适配的作用
05 函数对象(仿函数:进行定制化操作
06 空间配置器(对空间的申请和释放进行管理

02 序列式容器包括哪些?他们之间有哪些异同?

01 vector 可变数组
02 deque 双向队列
03 list 双向链表
04 foward_list 单向链表
05 array 数组

内存上,array 和 vector是一片连续的空间,其余是逻辑上连续,物理存储时分散的

实现上,vector底层通过三个指针实现,分别指向第一个元素的位置,最后一个元素的下一个位置,最后一个空间的下一个位置;
deque的实现依靠  中控器数组Map+小片段实现的,片段内部是连续的,片段与片段之间是不连续的,当deque需要扩容时,直接对Map进行扩容,申请新的小片段(小片段成员包括四个指针,分别指向第一个元素,最后一个元素,当前元素,一个指针用于和Map进行联系)
list 链表喵

使用上,deque,vector支持随机访问,list不支持

03 下面程序有什么错误?

list<int> lst; 
list<int>::iterator iter1 = lst.begin(), iter2 = lst.end(); 
while(iter1 < iter2)
{    //....
}

list的迭代器不能进行<比较,要用迭代器特有的!=

list%E5%86%99%E5%87%BA%E6%9D%A5">04 创建和初始化vector的方法,每种都给出一个实例?当然也可以把deque与list写出来

01 创建空容器
02 count个value
03 迭代器
04 {}
05 拷贝构造和移动构造

#include <iostream>
#include <vector>
#include <deque>
#include <list>
using std::cout;
using std::endl;
using std::vector;
using std::list;
using std::deque;template <class T>
void print( T & con){for(auto & ele: con){cout<<ele<<" ";}cout<<endl;
}void test(){/*1*/vector<int> num0;/*2*/vector<int> num1(10,5);//count same valueint arr[10]={0,1,2,3,4,5,6,7,8,9};/*3*/vector<int> num2(arr,arr+10);//[0,10)/*4*/vector<int> num4(num1);/*4*/vector<int> num5(vector<int>{1,2,3});/*5*/vector<int> num3{4,5,6,3,2,7,3,9};print(num0);print(num1);print(num2);print(num3);print(num4);print(num5);cout<<endl;
}
void test1(){/*1*/deque<int> num0;/*2*/deque<int> num1(10,5);//count same value/*3*/deque<int> num2(num1.begin(),num1.end());//[0,10)/*4*/deque<int> num4(num1);/*4*/deque<int> num5(deque<int>{1,2,3});/*5*/deque<int> num3{4,5,6,3,2,7,3,9};print(num0);print(num1);print(num2);print(num3);print(num4);print(num5);cout<<endl;
}
void test2(){/*1*/list<int> num0;/*2*/list<int> num1(10,5);//count same value/*3*/list<int> num2(num1.begin(),num1.end());//[0,10)/*4*/list<int> num4(num1);/*4*/list<int> num5(list<int>{1,2,3});/*5*/list<int> num3{4,5,6,3,2,7,3,9};print(num0);print(num1);print(num2);print(num3);print(num4);print(num5);cout<<endl;
}
int main(void)
{test();test1();test2();return 0;
}

05 如果c1与c2是两个容器,下面的比较操作有什么限制?if(c1 < c2)

01,是相同的容器类型
02,容器的元素类型支持比较操作
03,容器内部元素的顺序性比较(deque,vector支持,list不支持,只能使用!=)
04,容器支持随机访问元素

06 STL中的std::deque容器的实现原理?

deque的实现依靠  中控器数组Map+小片段实现的,片段内部是连续的,片段与片段之间是不连续的,当deque需要扩容时,直接对Map进行扩容,申请新的小片段(小片段成员包括四个指针,分别指向第一个元素,最后一个元素,当前元素,一个指针用于和Map进行联系)

07 评委打分的例子:要求:有五名选手ABCDE,10个评委打分,去掉最高分和最低分,求出每个选手的平均分。

思路: 

1.创建Person类,定义name,score成员属性;创建五名选手存放到vector容器中;

2.遍历vector容器,首先10个评委的打分存放到deque容器中,sort算法对分数排序,去掉最高最低分;

3.deque容器遍历,进行剩余分数的累加,求平均;

4.输出每个选手的姓名,成绩

提示:还是容器vector与deque的基本使用

//嘻嘻,每一个初始化都会worning#include <iostream>
#include <vector>
#include <deque>
#include <string.h>
#include <random>
using std::cout;
using std::endl;
using std::vector;
using std::deque;
using std::ostream;#define  PER_NUM 5
#define  SCO_NUM 10class Person{
public:
//const char* 坏,终于知道为什么worning了Person(char* name,int sc):_name(new char[strlen(name)+1]()),_score(sc){strcpy(_name,name);}Person(const Person & p):_name(new char[strlen(p._name)+1]()),_score(p._score){strcpy(_name,p._name);}//vector初始化使用拷贝构造~Person(){if(_name){delete []  _name;_name=nullptr;}}Person & operator=(const Person & p){if(this!=&p){delete [] _name;_name=new char[strlen(p._name)+1]();strcpy(_name,p._name);_score=p._score;}return *this;}void p_sc(int sc){_score=sc;}friend ostream & operator<<(ostream & os,const Person & p);
private:char* _name;int _score;
};
ostream & operator<<(ostream & os,const Person & p){os<<p._name<<"--"<<p._score<<"  ";return os;
}//-------------------------//
void test(){Person p1("xixi",0);Person p2("jiajia",0);Person p3("kewu",0);Person p4("dada",0);Person p5("shazi",0);vector<Person> people{p1,p2,p3,p4,p5};std::random_device rd;//获取随机数种子std::mt19937 gen(rd());//生成随机数引擎std::uniform_int_distribution<> dis(60,100);//范围for(int i=0;i<PER_NUM;i++){deque<int> sc;for(int j=0;j<SCO_NUM;j++){sc.push_back(dis(gen));/* cout<<sc[j]<<" "; */}/* cout<<endl; */int max=0,min=0,rel=0;for(auto & ele:sc){if(ele>max){max=ele;}if(ele<min){min=ele;}rel+=ele;}rel=(rel-max-min)/(SCO_NUM-2);people[i].p_sc(rel); cout<<people[i]<<endl;}cout<<endl;
}
int main(void)
{test();return 0;
}
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>using namespace std;class Person 
{
public:Person(const string &name,int score) : _name(name), _score(score){}string _name;int _score;
};void creatPerson(vector<Person>& vec) 
{string nameSeed = "ABCDE";for (int idx = 0; idx < 5; ++idx){string name = "选手";name += nameSeed[idx];int score = 0;Person p(name, score);vec.push_back(p);}
}void setScore(vector<Person>& vec)
{for (vector<Person>::iterator it = vec.begin(); it != vec.end(); ++it){deque<int> dq;for (int idx = 0; idx < 10; ++idx) {//将分数设定在[60, 100]范围中int score = ::rand() % 41 + 60;//产生随机的分数dq.push_back(score);}//对分数进行排序sort(dq.begin(), dq.end());dq.pop_front();//去掉最低分dq.pop_back();//去掉最高分int sum = 0;for (deque<int>::iterator dit = dq.begin(); dit != dq.end(); ++dit){sum += *dit;}//求10个评委的平均分int avg = sum/dq.size();//然后将10个评委的平均分赋值给每个选手it->_score = avg;	}
}void showScore(vector<Person>& vec) 
{for (vector<Person>::iterator it = vec.begin(); it != vec.end(); ++it) {cout << "姓名:" << it->_name << "  平均分数:" << it->_score << endl;}
}int main() 
{//种随机种子::srand(::clock());//定义Person类型的容器vector<Person> vec;//创建五名选手,创建容器类里面的成员及其属性creatPerson(vec);//给每个选手设定分数(让10个评委打分)setScore(vec);//显示每个选手的分数showScore(vec);	return 0;
}

 不想看,虽然我的初始化一直woring
//Person(const char* name,int score)坏,终于知道为什么worning了

08 编程题:从一个 vector<char> 初始化一个 string

提示:可以定义vector如下:vector<char> vc = { 'H', 'E', 'L', 'L', 'O' };然后查看如何给string进行初始化或者赋值,考查对vector与string的基本使用

#include <iostream>
#include <vector>
#include <deque>
#include <list>
#include <string>
using std::cout;
using std::endl;
using std::vector;
using std::list;
using std::deque;
using std::string;//---------------------------------//void test(){vector<char>vc={'h','e','l','l','o'};string s1{'\0'};cout<<s1<<endl;for(auto & ele:vc){s1+=ele;}s1+='\0';cout<<s1<<endl;
}int main(void)
{test();return 0;
}
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{vector<char> vc = { 'H', 'E', 'L', 'L', 'O' };string s(vc.data(), vc.size());cout << s << endl;return 0;
}

 我好蠢嘻嘻

09 题目:使用vector打印九九乘法表。

提示:可以使用vector嵌套vector的使用方式。例如:vector<vector<int>>,然后就是veector的基本操作。

#include <iostream>
#include <vector>
#include <deque>
#include <list>
#include <string>
using std::cout;
using std::endl;
using std::vector;
using std::list;
using std::deque;
using std::string;//---------------------------------//void print(vector<vector<int>>  & con){for(int i=0;i<9;i++){for(auto & ell : con[i]){cout<<(i+1)<<"×"<<ell<<"="<<(i+1)*(ell)<<"  ";}cout<<endl;}   
}//---------------------------------//
void test(){vector<vector<int>> v1(9);for(int i=0;i<9;i++){vector<int> tempv;for(int j=0;j<=i;j++){tempv.push_back(j+1);}v1[i]=tempv;}print(v1);
}int main(void)
{test();return 0;
}
#include<iostream>
#include<vector>using namespace std;int main()
{vector<vector<int> >v2d;for (int i = 0; i < 9; i++){v2d.push_back(vector<int>());}for (int i = 0; i < v2d.size(); i++){for (int j = 0; j <= i; j++){v2d[i].push_back((i + 1) * (j + 1));}}for (int i = 0; i < v2d.size(); i++){for (int j = 0; j < v2d[i].size(); j++){cout << i + 1 << "*" << j + 1 << "=" << v2d[i][j] << "\t";}cout << endl;}return 0;
}

01,初始化9个空 vector<int>-->vector<vector<int>>

02,vector<int>存乘积

03,打印


http://www.ppmy.cn/news/1521798.html

相关文章

OpenCV Jet颜色映射和HSV颜色空间对比

目录 一、概述 二、Jet颜色空间映射 2.1优势 2.2颜色变化范围 2.3应用场景 三、HSV 颜色空间 3.1优势 3.2颜色分布 3.3应用场景 四、Jet与HSV区别 4.1对比总结 4.2选择建议 OpenCV图像处理与应用实战算法汇总地址&#xff1a; OpenCV 图像处理应用实战算法列表汇总…

Elasticsearch 再次开源

作者&#xff1a;来自 Elastic Shay Banon [D.N.A] Elasticsearch 和 Kibana 可以再次被称为开源了。很难表达这句话让我有多高兴。我真的激动得跳了起来。Elastic 的所有人都是这样的。开源已经融入我的 DNA&#xff0c;也融入了 Elastic 的 DNA。能够再次将 Elasticsearch 称…

电脑回收站被清空,怎么恢复丢失数据?

回收站&#xff0c;这个看似不太起眼的电脑功能&#xff0c;实际上在关键时刻能够为我们挽回重大损失&#xff0c;帮助我们重新获得至关重要的文件和数据。对于经常与电脑打交道的朋友们来说&#xff0c;当某个文件被不小心删除时&#xff0c;回收站往往成为我们文件找回和恢复…

【实战案例】项目经理和产品经理高效配合的秘诀:产品与项目关联

最近&#xff0c;不断收到关于项目经理岗位以及产品经理岗位相关的提问&#xff0c;比如&#xff1a; “产品经理和项目经理&#xff0c;有什么区别&#xff1f;” “产品经理和项目经理&#xff0c;哪个发展前景更好&#xff1f;” “产品经理和项目经理发生冲突&#xff0…

开源云原生数据库PolarDB PostgreSQL 15兼容版本正式发布

开源云原生数据库PolarDB PostgreSQL 15兼容版正式发布上线&#xff0c;该版本100%兼容开源PostgreSQL 15。PolarDB是阿里云自研云原生关系型数据库&#xff0c;基于共享存储的存算分离架构使其具备灵活弹性和高性价比的特性&#xff0c;在开源PostgreSQL很好的性能表现的基础上…

Matlab 并联双振子声子晶体梁结构带隙特性研究

参考文献&#xff1a;吴旭东,左曙光,倪天心,等.并联双振子声子晶体梁结构带隙特性研究[J].振动工程学报,2017,30(01):79-85. 为使声子晶体结构实现范围更宽的多带隙特性&#xff0c;基于单振子型声子晶体结构弯曲振动带隙频率范围窄的局 限&#xff0c;提出了一种双侧振子布置…

监理工程师职业资格考试

根据住房城乡建设部、交通运输部、水利部、人力资源社会保障部关于印发《监理工程师职业资格制度规定》《监理工程师职业资格考试实施办法》&#xff08;建人规〔2020〕3号&#xff09;文件精神&#xff0c;监理工程师职业资格考试实行全国统一大纲、统一命题、统一组织。 一、…

TikTok直播为什么要用独立IP

TikTok直播作为一种受欢迎的社交媒体形式&#xff0c;吸引了越来越多的用户和内容创作者。在进行TikTok直播时&#xff0c;选择使用独立IP地址是一种被广泛推荐的做法。本文将探讨为什么在TikTok直播中更推荐使用独立IP&#xff0c;并解释其优势和应用。 独立IP是指一个唯一的互…

Linux是如何收发网络包的

Linux网 络协议栈 从上述⽹络协议栈&#xff0c;可以看出&#xff1a; 收发流程 ⽹卡是计算机⾥的⼀个硬件&#xff0c;专⻔负责接收和发送⽹络包&#xff0c;当⽹卡接收到⼀个⽹络包后&#xff0c;会通过 DMA 技术&#xff0c;将⽹络包放⼊到 Ring Buffer &#xff0c;这个是…

Identifying User Goals from UI Trajectories论文学习

通过UI轨迹识别用户的需求。 这篇论文同样聚焦于UI agent&#xff0c;只是思路比较特别。他们想要通过训练agent通过用户的行为轨迹反推出他们想要干什么的能力来锻炼agent识别&#xff0c;理解&#xff0c;使用UI的能力。同时这个训练项目本身也有一定的实际意义&#xff0c;…

RISC-V单片机智能落地扇方案

在众多产品中&#xff0c;智能落地扇产品凭借其出色的性能和质量优势&#xff0c;备受消费者青睐。智能落地扇有着卓越的性能和智能化的操作。 RAMSUN提供的智能落地扇方案主控单片机芯片采用RISC-V微处理器&#xff0c;内置高速存储器&#xff0c;最高工作频率可达144MHz&…

Mac基本使用记录

快捷键 将窗口拆分为两个面板Command-D关闭拆分面板Shift-Command-D 打开任务管理器 基本操作 在 Mac 上使用桌面叠放 - 官方 Apple 支持 (中国) commandc 复制 commandv 粘贴 聚焦 快捷键 commandspace 可以用于搜索文件&#xff0c;应用和网页等内容。 也…

TOMCAT实验

TOMCAT 一、TOMCAT功能介绍 1.1 安装TOMCAT 配置Java环境 [roottomcat1 ~]# yum install java-1.8.0-openjdk.x86_64 -y [roottomcat2 ~]# dnf install java-1.8.0-openjdk.x86_64 -yJava环境被存放在 /etc/alternatives/目录下 [roottomcat1 ~]# ls /etc/alternatives/…

软件测试 - 性能测试 (概念)(并发数、吞吐量、响应时间、TPS、QPS、基准测试、并发测试、负载测试、压力测试、稳定性测试)

一、性能测试 目标&#xff1a;能够对个人编写的项目进行接口的性能测试。 一般是功能测试完成之后&#xff0c;最后做性能测试。性能测试是一个很大的范围&#xff0c;在学习过程中很难直观感受到性能。 以购物软件为例&#xff1a; 1&#xff09;购物过程中⻚⾯突然⽆法打开…

Java项目: 基于SpringBoot+mysql+mybatis校园管理系统(含源码+数据库+答辩PPT+毕业论文)

一、项目简介 本项目是一套基于SpringBootmysql校园管理系统 包含&#xff1a;项目源码、数据库脚本等&#xff0c;该项目附带全部源码可作为毕设使用。 项目都经过严格调试&#xff0c;eclipse或者idea 确保可以运行&#xff01; 该系统功能完善、界面美观、操作简单、功能齐…

visual studio 2022更新以后,之前的有些工程编译出错,升级到Visual studio Enterprise 2022 Preview解决

系列文章目录 文章目录 系列文章目录前言一、解决方法 前言 今天遇到一个问题&#xff1a;visual studio 2022升级成预览版以后&#xff0c;之前的有些工程编译出错。首先代码、项目设置都没有改变&#xff0c;只是更新了visual studio 2022。 在编译工程时&#xff0c;编译器…

【HTTP、Web常用协议等等】前端八股文面试题

HTTP、Web常用协议等等 更新日志 2024年9月5日 —— 什么情况下会导致浏览器内存泄漏&#xff1f; 文章目录 HTTP、Web常用协议等等更新日志1. 网络请求的状态码有哪些&#xff1f;1&#xff09;1xx 信息性状态码2&#xff09;2xx 成功状态码3&#xff09;3xx 重定向状态码4&…

2024国赛数学建模评价类算法解析,2024国赛数学建模C题思路模型代码解析

2024国赛数学建模评价类算法解析&#xff0c;2024国赛数学建模C题思路模型代码解析&#xff1a;9.5开赛后第一时间更新&#xff0c;更新见文末名片 1 层次分析法 基本思想 是定性与定量相结合的多准则决策、评价方法。将决策的有关元素分解成目标层、准则层和方案层&#xff…

UDP通信实现

目录 前言 一、基础知识 1、跨主机传输 1、字节序 2、主机字节序和网络字节序 3、IP转换 2、套接字 3、什么是UDP通信 二、如何实现UDP通信 1、socket():创建套接字 2、bind():绑定套接字 3、sendto():发送指定套接字文件数据 4、recvfrom():接收指定地址信息的数据 三…

2024.9.6

1> 手写unique_ptr智能指针 #include <iostream> //#include <memory> using namespace std; //unique_ptr<AA> p0(new AA("西施"));// 分配内存并初始化。 template <typename T> class unique_ptr { public:explicit unique_ptr(T p) …