链表函数

#include"node.h"
#include
#include

//typedef struct _node{
//  int value;
//  struct _node *next;
//} Node; 

typedef struct _list{
    Node *head;//不要写成struct _list *head;
    //Node *tail;
} List;
void add(List *pList,int number);

int main(int argc, char const *argv[])
{
    List list;
     
    list.head=NULL;//使用结构体,以前:Node *head=NULL;
    int number;
    do{
        scanf("%d",&number);
        if(number!=-1){
            
            list.head=add(&list,number);
            }
        }while(number!=-1);
     return 0; 
} 

void add(List *pList,int number)
{ 
    //add to linked-list
    Node *p=(Node*)malloc(sizeof(Node));
    p->value=number;
    p->next=NULL;
    //find the last
    Node *last=pList->head;//以前Node *last=head;
    if(last)//last不为空
    {
        while(last->next)
        {
            last=last->next;
        }
            //attach
         last->next=p;
        
     } 
     else
     {
        pList->head=p; 
     }
     
}   
    

有报错,还未解决

你可能感兴趣的:(链表函数)