链表的建立

问题描述:

链表建立里的一点理解

#include 
#include 
typedef struct line
{
     
    int a;
    struct line *next;
}LINE;
int main()
{
     
    LINE *head,*now,*tmp;
    int i = 0, j = 0;
    head = now = malloc(sizeof(LINE));
    for(i=0;i<10;i++)
    {
     
        now->a=i+1;
        now->next=malloc(sizeof(LINE));//为next分配内存;
        now = now->next;//这里是将“下一个”now的地址存入next中;
    }
    now->next=NULL;
    tmp = head;
    for(i=0;i<10;i++)
    {
     
        printf("%d\n",tmp->a);
        tmp = tmp->next;//这里是将next中已存入的地址取出到新的tmp中;
    }
    return 0;
}


原因分析:

挖坑

解决方案:

有空就补

你可能感兴趣的:(链表的建立)