#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node* next;
};
void appendToList(struct Node head, int newData) {
struct Node newNode = (struct Node)malloc(sizeof(struct Node));
struct Node last = head;
newNode->data = newData;
newNode->next = NULL;
if (*head == NULL) {
*head = newNode;
return;
}
while (last->next != NULL) {
last = last->next;
}
last->next = newNode;
}
void printList(struct Node* node) {
while (node != NULL) {
printf("%d ", node->data);
node = node->next;
}
}
int main() {
struct Node* head = NULL;
appendToList(&head, 1);
appendToList(&head, 2);
appendToList(&head, 3);
printf("Linked List: ");
printList(head);
return 0;
}