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

边栏推荐
- 涂鸦Wi-Fi&BLE SoC开发幻彩灯带
- DAY17, CSRF vulnerability
- Golang channel implementation principle
- WPF introduces ttf icon file usage record
- mysql隔离级别
- [Awards every week] The "Edge Containers" track of the Cloud Native Programming Challenge invites you to fight!
- 聊一聊什么是SaaS,以及遇到的问题......
- Get the local IP and Request's IP
- (Problem practice) Conditional probability + weight line segment tree + FWT + suffix array
- 【 notes 】 the beauty of the software engineering - column 31 | software testing are responsible for the quality of products?
猜你喜欢

KubeMeet Registration | The complete agenda of the "Edge Native" Online Technology Salon has been announced!

Learning of redis_Basic part

WPF study notes "WPF Layout Basics"

GO语言学习笔记一

Code readability, pre-checks, comments and summaries

3. Dependency configuration management
Go study notes (84) - Go project directory structure

1315_Use the LOOPBACK simulation mode to test whether the pyserial installation is successful

小程序使用npm包定制全局样式

Simple experiment with BGP
随机推荐
BindingExpression path error: 'selectMenusList' property not found on 'object' ''ViewModel'
Classification of decision tree classification
C. Qualification Rounds
Discourse 自定义头部链接(Custom Header Links)
Catch That Cow(详解)
双指针问题(上)
Requirements design document and the changing role of the product manager
Stimulsoft ReportsJS and DashboardsJS. 2022.3.3
mysql无法远程连接 Can‘t connect to MySQL server on ‘xxx.xxx.xxx.xxx‘ (10060 “Unknown error“)
protobuf 中复合数据类型的读写
Small programs use npm packages to customize global styles
WPF recursively obtains the list of specified control types in the form
涂鸦Wi-Fi&BLE SoC开发幻彩灯带
Perspective transformation matrix of image perspective correction should be matrix (single)/findHomography with getPerspectiveTransformd difference
Get the local IP and Request's IP
模拟问题(下)
DAY17: weak password detection and test
[Awards every week] The "Edge Containers" track of the Cloud Native Programming Challenge invites you to fight!
Solve the error SyntaxError: (unicode error) 'utf-8' codec can't decode byte 0xb7 in position 0: invalid start b
DAY17, CSRF vulnerability