struct Node* buildLinkedList(int* arr, int n)
{
//创建哨兵位
struct Node* head = (struct Node*)malloc(sizeof(struct Node));
head->link = NULL;
struct Node* node = NULL;
for (int i = 0; i < n; i++)
{
//循环创建每一个结点
node = (struct Node*)malloc(sizeof(struct Node));
node->data = arr[i];
//连接
node->link = head->link;
head->link = node;
}
return head;
}
void printLinkedList(struct Node* head)
{
//输出第一个值
head = head->link;
printf("%d", head->data);
head = head->link;
while (head)
{
printf(" %d", head->data);
head = head->link;
}
}