
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;
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33