In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how C++ customizes the one-way linked list ListNode, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
There are two types of linked lists:
1, the lead node, the head node stores the length of the linked list, and the data is stored from the second node.
2. There is no lead node, no node that stores the length of the linked list, and data is stored from the head node.
The linked list defined here is the second one.
Go directly to the code:
# include # include using namespace std;struct ListNode {int val; / / value of the current node ListNode * next / / pointer to the next node ListNode (): val (0), next (nullptr) {} / / initializes the current node value to the default value of 0, the pointer to null ListNode (int x): val (x), next (nullptr) {} / / initializes the current node value to x, and the pointer to null ListNode (int x, ListNode * next): val (x) Next (next) {} / / initialize the current node value is x, and the next grade point is next} Class Solution {public: / / create an one-way linked list void createList (ListNode * head,int len) with the length of len {for (int inode 1 / ivalidi; / / assign the value node- > next=nullptr; head- > next=node; / / head to the next node (that is, the current node) head=node; / / set the current node to head} cout
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.