#include <stdio.h>
#include <stdlib.h>

typedef struct Node{

        int data;
        struct Node* next;
        
    }Node;
    
Node* createNode(int val){
    Node* n=(Node *)malloc(sizeof(Node));
    n->data=val;
    n->next=NULL;
    return n;
}
void insertAtEnd(Node** head,int val){
    Node* newNode=createNode(val);
    if(*head==NULL){
        *head=newNode;
        (*head)->next=*head;
        return;
    }
    Node* temp=*head;
    while(temp->next!=*head){
        temp=temp->next;
        
    }
    temp->next=newNode;
    newNode->next=*head;
}
void display(Node* head){
    Node* temp=head;
    do(temp!=head){
        printf("%d->",temp->data);
        temp=temp->next;
        
    }while(temp!=head);
    
}
int main(){
    Node* head=NULL;
    insertAtEnd(&head,10);
    insertAtEnd(&head,20);
    insertAtEnd(&head,30);
    insertAtEnd(&head,40);
    insertAtEnd(&head,50);
    display(head);
    return 0;
}