/*使用头插法建立单链表,并返回指向单链表的头结点的指针*/
Node *CreateAtHead(DataType a[],int n)
{
int i;
/*********Begin************/
struct Node*p,*head;
head=(struct Node*)malloc(sizeof(struct Node));
head->next=NULL;
for(int i=0;i<n;i++){
p=(struct Node*)malloc(sizeof(struct Node));
p->data=a[i];
p->next=head->next;
head->next=p;
}
return head;
/*******End**************/
}
头插法建立单链表educoder
最新推荐文章于 2024-10-03 19:13:18 发布