Circular linked list

Q1)
sir, why am i getting segment fault in my code in this site , it is working fine in my vs code .

Code -> https://sapphireengine.com/@/r2ityi

Q2)
And how the below loop is giving the last element of circular list .
(temp->next!=head)
as when temp is in last element then next is pointing to head , so it should get out of the loop,

temp->next!=head
ur this line is giving error… u have created a normal linked list and trying to traverse it assuming circular list…
temp->next!=NULL make this change
also in insertathead function
if(head == NULL){
Node* n=new Node(data);
head = n;
}
add this as the base case…

is ur doubt cleared???

temp->next!=head ur this line is giving error… u have created a normal linked list and trying to traverse it assuming circular list… temp->next!=NULL make this change also in insertathead function if(head == NULL){ Node* n=new Node(data); head = n; } add this as the base case…

sir how temp!=NULL is giving me correct output, isn’t itthe normsl linked linked ?

sir, but in circular list , the temp->next should point to Head and not NULL ,

bro if u want to implement circular linked list from where do u think u have implemented the code for the same… all u are doing is simply writing code for normal linked list
https://ide.codingblocks.com/s/603154 i have made changes in ur code… now its working fine as circular list…

i hope now ur doubt is cleared??

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.