#include<stdio.h>
#include<stdlib.h>

typedef struct Node {
    int data;
    struct Node* next;
} Node;

Node* createNode(int data){
    Node* newNode =(Node*)malloc(sizeof(Node));
    if(!newNode){
        printf("Memory error\n");
        return NULL;
    }
    
    newNode->data = data;
    newNode-> next =NULL;
    return newNode;
}

void insertNode(Node** head, int data){
    Node* newNode = createNode(data);
    if(*head == NULL){
        *head = newNode;
        return;
    }
    Node* last = *head;
    while(last->next){
        last = last->next;
    }
    last ->next = newNode;
}

void displaylidt(Node* head){
    Node* temp = head;
    while (temp != NULL){
        printf("%d ", temp ->data);
        temp = temp -> next;
    }
    printf("\n");
}

int main(){
    Node* head = NULL;
    int n, value;
    
    printf("Enter number of nodes: ");
    scanf("%d", &n);
    
    for(int i = 0;i < n ; i++){
        printf("Enter value for node %d :", i + 1);
        scanf("%d", &value);
        insertNode(&head, value);
    }
    
    printf("Linked list: ");
    displayList (head);
    
    return 0;
    
}