链表问题
#define NULL 0
struct list
{
int data;
struct list *next;
};
struct list *Create_list(v,n)
int v[],n;
{
void *malloc();
struct list *head,*p,*q;
int i;
if (n<0)
return(NULL);
q = (struct list *)malloc(sizeof(struct list));
q->data = v[0];
head = q;
printf("/n%d",head->data);
for(i=1;i<n;i++)
{
p = (struct list *)malloc(sizeof(struct list));
q->data = v[i];
q->next = p;
q = p;
}
q->next = NULL;
return(head);
}
main()
{
struct list *Create_list(),*head;
int v[] = {1,2,3,4,5,6};
head = Create_list(v,6);
printf("\n%d",head->data);
}
为什么输出值是1,2
而不是1,1