当前位置:网站首页>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;
}

边栏推荐
猜你喜欢
![[High Performance Computing] openMP](/img/a5/2cfd760a26edb379d337eb3d1605d5.jpg)
[High Performance Computing] openMP

VisualStudio2022 local debugging entry is particularly slow problem solving

七、自定义配置

三、依赖配置管理

ThinkPHP高仿蓝奏云网盘系统源码/对接易支付系统程序

2.6 Radix sort (bucket sort)

Naive Bayes Classification

Classification of decision tree classification

Xiamen SenseCore Technology MC3172(1): Introduction and Environment Construction

IGBT wafers used in photovoltaic inverters
随机推荐
The 2nd Shanxi Province Network Security Skills Competition (Enterprise Group) Part of the WP (9)
涂鸦Wi-Fi&BLE SoC开发幻彩灯带
Image stitching (registration) case based on OpenCV
C. Travelling Salesman and Special Numbers (binary + combination number)
L2-025 分而治之
KubeMeet Registration | The complete agenda of the "Edge Native" Online Technology Salon has been announced!
mysql隔离级别
Machine Learning: Knowing the Dimensionality Reduction Process Through Low Variance Filtering
SVN View Username and Password
ms project2010项目管理软件使用技巧总结
Seven, custom configuration
C语言实现安全性极高的游戏存档并读档
4. Web Development
Protobuf compound data types, speaking, reading and writing
Solve the error SyntaxError: (unicode error) 'utf-8' codec can't decode byte 0xb7 in position 0: invalid start b
LeetCode Algorithm 328. Parity linked list
三、依赖配置管理
LeetCode Algorithm 2326. 螺旋矩阵 IV
Discourse Custom Header Links
VisualStudio2022本地调试进入特别慢问题解决