栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

【Leecode笔记05-数据结构入门14天】初学自用笔记-链表和指针

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【Leecode笔记05-数据结构入门14天】初学自用笔记-链表和指针

关于指针,菜鸟家的表述比较清晰了【https://www.runoob.com/cplusplus/cpp-pointers.html】


链表:
转载自【http://c.biancheng.net/view/1570.html】 还没太懂:

因为指向链表头的指针用于定位链表的头部,所以也可以认为它代表了链表头。同样的指针也可以用来定位整个链表,从头开始,后面跟着后续指针,所以也可以很自然地把它看作是代表了整个链表。

这个看起来很实用!
给到的一个实例程序,需要常看常新:

// This program illustrates the building
// and traversal of a linked list.
#include 
#include 
using namespace std;
struct ListNode
{
    double value;
    ListNode *next;
    // Constructor
    ListNode(double value1, ListNode *next1 = nullptr)
    {
        value = value1; next = next1;
    }
};

int main()
{
    double number; // Used to read the file
    ListNode *numberList = nullptr; // List of numbers
    // Open the file
    ifstream numberFile("numberFile•dat");
    if (!numberFile)
    {
        cout << "Error in opening the file of numbers.";
        exit (1);
    }
    //Read the file into a linked list
    cout << "The contents of the file are: " << endl;
    while (numberFile >> number)
    //>>表示读入数据到number,如果读取值非空,则进行操作
    {
        cout << number << " ";
        // Create a node to hold this number
        numberList = new ListNode(number, numberList);
    }
    // Traverse the list while printing
    cout << endl << "The contents of the list are: " << endl;
    ListNode *ptr = numberList;
    while (ptr != nullptr)
    {
        cout << ptr->value << " "; // Process node
        ptr = ptr->next; // Move to next node
    }
    return 0;
}


类似的原理&题目思路解释见【https://blog.csdn.net/weixin_39538889/article/details/85801412】,眼睛痛还没看

auto

在C++11标准的语法中,auto被定义为自动推断变量的类型。
不过C++11的auto必须给申明的变量赋予一个初始值,否则会报错。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/630302.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号