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);

  • 相关阅读:
    慕课前端入门-HTML5属性变化
    黑马jQuery教程4
    黑马jQuery教程3
    黑马JQuery教程2
    2017-03-15
    按钮图标化
    AES MFC实现
    CButtonST类简介使用方法
    VS资源编辑器常见错误RC1000到RC1208
    MFC单文档程序添加HTML帮助支持
  • 原文地址:https://www.cnblogs.com/cmyg/p/6618933.html
Copyright © 2011-2022 走看看