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

边栏推荐
- mysql isolation level
- Unity beginner 5 cameras follow, border control and simple particle control (2 d)
- Simulation problem (middle)
- Catch That Cow(详解)
- Simple experiment with BGP
- Boss Rush (two-point answer + DP)
- Chapter8 Support Vector Machines
- 模拟问题(上)
- QT(39)-vs development qt program prompts that the source file cannot be opened
- Requirements design document and the changing role of the product manager
猜你喜欢

3. Dependency configuration management

2.5 Quick Sort

Naive Bayes Classification

Stimulsoft ReportsJS and DashboardsJS. 2022.3.3

全流程调度——Azkaban入门与进阶

七、自定义配置

动态规划问题(完结篇)

The Azure developer news 丨 memorabilia in July
![[Awards every week] The](/img/78/4b510b190475d603490614d2c8199f.png)
[Awards every week] The "Edge Containers" track of the Cloud Native Programming Challenge invites you to fight!

ThinkPHP高仿蓝奏云网盘系统源码/对接易支付系统程序
随机推荐
webService interface
POJ1321 chessboard problem (detailed explanation)
Intermediate - interview questions
Alibaba Cloud's EasyNLP Chinese text image generation model takes you to become an artist in seconds
WPF introduces ttf icon file usage record
Excellent MySQL interview questions, 99% must ask in preparation for August!I can't pass the interview
Discourse Custom Header Links
Hexagon_V65_Programmers_Reference_Manual(10)
The Complete Go Books - Beginner to Advanced and Web Development
动态规划问题(完结篇)
Verify that the addShutdownHook hook takes effect
ThinkPHP高仿蓝奏云网盘系统源码/对接易支付系统程序
(Hexagon_V65_Programmers_Reference_Manual(13)
Go study notes (84) - Go project directory structure
Stimulsoft ReportsJS and DashboardsJS. 2022.3.3
Compound Types--references, pointers
The 2nd Shanxi Province Network Security Skills Competition (Enterprise Group) Part of the WP (9)
LeetCode Algorithm 2326. Spiral Matrix IV
Simple experiment with BGP
SVN View Username and Password