My Code for insertion and deletion in Circular LL is not working

#include
using namespace std;

class Node{
public:
int data;
Node* next;

Node(int data){
	this->data = data;
	this->next = NULL;
}

};

Node* insert(Node* head, int data){
Node* n = new Node(data);
Node* temp = head;

n->next = head;

if(temp!=NULL){
	while(temp->next!=head){
		temp=temp->next;
	}
	temp->next = head;

}
else{
	n->next = n;
}

head = n;

return head;

}

void print(Node* head){
Node* temp = head;
while(temp->next!=head){
cout<data<<" ";
temp = temp->next;
}
cout<data<<endl;
return;
}

Node* getNode(Node* head, int data){
Node* temp = head;
while(temp->next!=head){
if(temp->data==data){
return temp;
}
temp = temp->next;
}
if(temp->data==data){
return temp;
}
return NULL;
}

Node* deleteNode(Node* head, int data){
Node* del = getNode(head, data);
if(del==NULL){
return head;
}
if(head==del){
head = head->next;
}
Node* temp = head;
while(temp->next!=del){
temp = temp->next;
}
temp->next = del->next;
delete del;

return head;

}

int main(){
Node* head = NULL;
head = insert(head, 10);
head = insert(head, 20);
head = insert(head, 30);
head = insert(head, 40);
print(head);
return 0;
}

hi @RishabhK
refer this -->


I have implemented all functions of circular linked list over here…

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.