struct Node* buildLinkedList(int* arr, int n)
{
struct Node* head = malloc(n*sizeof(struct Node));
struct Node* p = head;
int i;
for(i = 0;i < n;i++)
{
struct Node* pc = malloc(sizeof(struct Node));
pc->data = arr[i];
pc->link = NULL;
p->link = pc;
p = pc;
}
return head;
}
/* 尾插法建立单链表 */;
void printLinkedList(struct Node* head)
{
struct Node* p =head->link;
int i = 0;
while(p)
{
if(i)
printf(" ");
i++;
printf("%d",p->data);
p = p->link;
}
} /* 打印链表 */