#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node* next;
};
void push(struct Node head_ref, int new_data) {
struct Node new_node = (struct Node)malloc(sizeof(struct Node));
new_node->data = new_data;
new_node->next = *head_ref;
*head_ref = new_node;
}
void printList(struct Node* node) {
while (node != NULL) {
printf("%d ", node->data);
node = node->next;
}
printf("\n");
}
struct Node copyLinkedList(struct Node original) {
if (original == NULL) return NULL;
struct Node new_list = (struct Node)malloc(sizeof(struct Node));
new_list->data = original->data;
new_list->next = copyLinkedList(original->next);
return new_list;
}
int main() {
struct Node* head = NULL;
push(&head, 4);
push(&head, 3);
push(&head, 2);
push(&head, 1);
printf("Original linked list: ");
printList(head);
struct Node* copiedList = copyLinkedList(head);
printf("Copied linked list: ");
printList(copiedList);
return 0;
}