当前位置:网站首页>Usage when saving pointers in std::vector
Usage when saving pointers in std::vector
2022-07-30 05:02:00 【Autodesk_Glodon】
#include "pch.h"
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <unordered_set>
using namespace std;
struct ListNode {
int num;
int score;
ListNode* next;
ListNode() : num(0), score(0), next(NULL) {
}
ListNode(int numV,int scoreV, ListNode* pNext)
{
num = numV;
score = scoreV;
next = pNext;
}
ListNode& operator = (const ListNode& pNode)
{
num = pNode.num;
score = pNode.score;
next = pNode.next;
}
/*bool operator == (const ListNode& pNode) { }*/
};
int main()
{
// 定义一个指针数组vector
vector<ListNode*> vecList;
ListNode* pHead = new ListNode(1001, 89, NULL);
vecList.push_back(pHead);
ListNode* pNode1 = new ListNode(1002, 78, NULL);
vecList.push_back(pNode1);
ListNode* pNode2 = new ListNode(1003, 94, NULL);
vecList.push_back(pNode2);
for (auto itor = vecList.begin(); itor != vecList.end(); ++itor)
{
if (*itor)
{
cout << (*itor)->num << " " << (*itor)->score << endl;
}
}
// 手动删除vecpointer contents in
delete pHead; pHead = nullptr;
delete pNode1; pNode1 = nullptr;
delete pNode2; pNode2 = nullptr;
//vecList.clear();
// check this timevecpointer contents in
cout << vecList.size() << endl;
for (auto itor = vecList.begin(); itor != vecList.end(); ++itor)
{
if (*itor)
{
cout << (*itor)->num << " " << (*itor)->score << endl;
}
}
return 0;
}
边栏推荐
- 【 notes 】 the beauty of the software engineering - column 31 | software testing are responsible for the quality of products?
- LeetCode Algorithm 328. 奇偶链表
- Hexagon_V65_Programmers_Reference_Manual(14)
- 双指针问题(上)
- Simulation problem (middle)
- Naive Bayes Classification
- Hexagon_V65_Programmers_Reference_Manual(12)
- Small programs use npm packages to customize global styles
- 模拟问题(下)
- Simulation problem (below)
猜你喜欢
六、读取应用配置+日志配置
[High Performance Computing] openMP
Hexagon_V65_Programmers_Reference_Manual(11)
webService接口
VisualStudio2022本地调试进入特别慢问题解决
std::vector中保存指针时用法
ms project2010项目管理软件使用技巧总结
Excellent MySQL interview questions, 99% must ask in preparation for August!I can't pass the interview
小程序使用npm包定制全局样式
小程序npm包--API Promise化
随机推荐
2.6 Radix sort (bucket sort)
Small program npm package--API Promise
解决报错SyntaxError: (unicode error) ‘utf-8‘ codec can‘t decode byte 0xb7 in position 0: invalid start b
双指针问题(中)
Unity踩坑记录 —— GetComponent的使用
WPF recursively obtains the list of specified control types in the form
webService interface
DAY17: weak password detection and test
file system two
Discourse Custom Header Links
1315_使用LOOPBACK模拟模式pyserial安装是否成功的测试
Plan for many situations in the processing chain
Stimulsoft ReportsJS and DashboardsJS. 2022.3.3
Three Solutions for SaaS Multi-tenant Data Isolation
1315_Use the LOOPBACK simulation mode to test whether the pyserial installation is successful
L2-020 功夫传人
Repetition XXL - JOB scheduling center background arbitrary command execution
【 notes 】 the beauty of the software engineering - column 31 | software testing are responsible for the quality of products?
Code readability, pre-checks, comments and summaries
四、Web开发