zoukankan      html  css  js  c++  java
  • 链表常用内容和易犯错误

     

    1.创建链表中没有分配空间

    for (i=1;i<=n;i++)

    {

    //遗漏,从而使链表的每一个数据的地址都一样

    s=(struct node *) malloc (sizeof(struct node));

    scanf("%ld",&s->data);

    s->next=p;

    p=s;

    }

    2.对指针赋值为空后又对指针的内容进行赋值

        struct node

        {

            long data;

            struct node *next;

        }*p;

        p=(struct node *) malloc (sizeof(struct node));

        p=NULL;

        p->data=1;//错误

     

    3.释放指针后又对指针进行操作

    free(p);

    p->data=1;//错误

    4.链表指针

     #include <malloc.h>

        struct node

        {

            long data;

            struct node *next;

        }*p;

        //本身已经是struct node *point,创建数组再加"*"

    //第一个括号为数据的类型(xxx的地址),所以为两个*;第二个括号为数据分配的单元(xxx)的数据类型,所以为一个*

    struct node **point=(struct node **) malloc (sizeof(struct node *)*100000);

  • 相关阅读:
    golang 中 sync包的 WaitGroup
    Go_20: Golang 中 time 包的使用
    mysql 同步数据到 ElasticSearch 的方案
    mysql 对应 binlog 查看
    python3.6爬虫总结-01
    Golang 之协程详解
    golang私服搭建
    Ubuntu vim设置
    密码校验规则
    golang密码校验
  • 原文地址:https://www.cnblogs.com/cmyg/p/6618933.html
Copyright © 2011-2022 走看看