当前位置:网站首页>std::vector中保存指针时用法
std::vector中保存指针时用法
2022-07-30 04:45:00 【欧特克_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;
}
}
// 手动删除vec中的指针内容
delete pHead; pHead = nullptr;
delete pNode1; pNode1 = nullptr;
delete pNode2; pNode2 = nullptr;
//vecList.clear();
// 检验此时vec中的指针内容
cout << vecList.size() << endl;
for (auto itor = vecList.begin(); itor != vecList.end(); ++itor)
{
if (*itor)
{
cout << (*itor)->num << " " << (*itor)->score << endl;
}
}
return 0;
}

边栏推荐
- Excellent MySQL interview questions, 99% must ask in preparation for August!I can't pass the interview
- Stimulsoft ReportsJS and DashboardsJS. 2022.3.3
- Go study notes (84) - Go project directory structure
- 【软件工程之美 - 专栏笔记】31 | 软件测试要为产品质量负责吗?
- Catch That Cow (detailed)
- Get the local IP and Request's IP
- 成为一个合格的网安,你知道这些吗?
- C# One Week Introductory "C# - Classes and Objects" Day Six
- 复现XXL-JOB 任务调度中心后台任意命令执行漏洞
- 双指针问题(中)
猜你喜欢

How with Mexico Volkswagen VW EDI connection to Mexico

Shanxi group (enterprises) in the second network security skills competition part problem WP (7)

Seven, custom configuration

QT(39)-vs development qt program prompts that the source file cannot be opened

【线性表】- LeetCode力扣三道练习题详解

unity初学5 摄像机跟随,边界控制以及简单的粒子控制(2d)

解决报错SyntaxError: (unicode error) ‘utf-8‘ codec can‘t decode byte 0xb7 in position 0: invalid start b

Classification of decision tree classification

The Azure developer news 丨 memorabilia in July

斐波那契数列的递归优化《备忘录递归》
随机推荐
GCC Rust is approved to be included in the mainline code base, or will meet you in GCC 13
- B + tree index and MySQL series 】 【 what is the difference between a HASH index
The 2nd Shanxi Province Network Security Skills Competition (Enterprise Group) Partial WP (10)
A must see for software testers!Database knowledge MySQL query statement Daquan
Some understanding of YOLOv7
Golang eight-legged text finishing (continuous handling)
js operation to add or subtract from the current date (day, week, month, year)
聊一聊什么是SaaS,以及遇到的问题......
error: The following untracked working tree files would be overwritten by
WPF study notes "WPF Layout Basics"
Become a qualified cybersecurity, do you know this?
VisualStudio2022 local debugging entry is particularly slow problem solving
Requirements design document and the changing role of the product manager
1. Get data - requests.get()
Simple experiment with BGP
MYSQL unique constraint
Golang channel implementation principle
mysql isolation level
Catch That Cow(详解)
mysql隔离级别