#include <stdio.h>
#include <stdlib.h>
struct Node {
    int data;
    struct Node*next;
};
struct Node*createNote(int data){
    struct Node*newNode =(struct Node*)malloc(sizeof(struct Node));
    if(!newNode) {
        printf("Memory allocation error!\n");
        exit(1);
    }
    newNode->data=data;
    newNode->next=NULL;
    return newNode;
}
void insertAtEnd(struct Node**head,int data){
    struct Node*newNode = createNote(data);
    if(*head==NULL){
        *head=newNode;
       } else{
            struct Node*temp=*head;
            while(temp->next!=NULL) 
                temp=temp->next;
       }
        }
        void displayList(struct Node*head){
            if(head==NULL){
                printf("List is empty.\n");
            }else {
                struct Node*temp=head;
                while(temp!=NULL){
                    printf("%d->",temp->data);
                    temp=temp->next;
                }
                printf("NULL\n");
            {
        
        void freeList(struct Node*head) {
            struct Node*temp;
            while(head!=NULL) {
                temp=head;
                head=head->next;
                free(temp);
}
}
int main() {
    struct Node*head=NULL;
    insertAtEnd(&head,10);
    insertAtEnd(&head,20);
    insertAtEnd(&head,30);
    printf("Linked list:");
    displayList(head);
    freeList(head);
    return 0;
}