WHY MY INSERT AT BEGINING is not working?

THIS IS MY CODE :-

why my insertatstart ( ) is not working?

At line number 67 ,
Your newnode->nextnode should point to head if your linked list is not empty. And after that update your head = newnode
And if your linked list is empty, just make a new node at make it as head of linked list.

hello sir this is circular linked list and FOR INSERTATSTART() , I have define new newnode and point it’s nextnode to tails->nextnode and updated the tail->nextnode=newnode. But when I recall display() function this is only printing newnode->data and terminates.

See the logic to insert in circular linked list is this

node *n = new node(d);
    node *temp=head;
    
    if(temp!=NULL){
        while(temp->next!=head){  
         temp = temp->next;       
        }
    temp->next = n;
    
    }
    else{
        n->next=n;  
        head=n;
    }
    n->next = head;

We would need head in function as we have to traverse on the linked list. I am not able to figure out the implementation as your code is in C, Though you can take reference from this and implement it on your code. If you have any issue with implementation part, feel free to ask :slight_smile:

Coding Blocks IDE please sir I have updated head function but please check it is not working still.

Have partially solved your code


Now only issue in it is after inserting new node at head, only the last element is not able to print cause of your implementation. I would suggest you to take idea from this code

and run this in your ide

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.