#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node* next;
};
struct Node* arrayToList(int arr[], int n) {
struct Node* head = NULL;
struct Node* temp = NULL;
for (int i = 0; i < n; i++) {
struct Node newNode = (struct Node)malloc(sizeof(struct Node));
newNode->data = arr[i];
newNode->next = NULL;
if (head == NULL) {
head = newNode;
temp = newNode;
} else {
temp->next = newNode;
temp = newNode;
}
}
return head;
}
void printList(struct Node* head) {
while (head != NULL) {
printf("%d -> ", head->data);
head = head->next;
}
printf("NULL\n");
}
int main() {
int arr[] = {1, 2, 3, 4, 5};
int n = sizeof(arr) / sizeof(arr[0]);
struct Node* head = arrayToList(arr, n);
printf("Linked List: ");
printList(head);
return 0;
}