It is giving me segmentation fault

is it because of the 2 loops which are used in the code.what is the reason and how can i improve it.

@anyamaurya Please provide me code in coding blocks IDE.
Also one common mistake is not making K=K%n
As K can be greater than n

#include<bits/stdc++.h>
using namespace std;

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

node(int d)
{
	data=d;
	next=NULL;
}

};

node* k_append(node*&head,int n,int k)
{ int k=k%n;
int l=n-k+1,i=0;
node* prev=NULL;
node* curr=head;
while(i<l)
{
prev=curr;
curr=curr->next;
i++;
}
prev->next=NULL;
nodetemp=curr;
while(temp!=NULL)
{
temp=temp->next;
}
temp->next=head;
temp=head;
return temp;
}
void print(node
head)
{
nodetemp=head;
while(temp!=NULL)
{
cout<data<<"–>";
temp=temp->next;
}
cout<<endl;
}
void insert(node
& head,int data)
{
if(head==NULL)
{
head=new node(data);
return;
}
node* tail=head;
while(tail!=NULL)
{
tail=tail->next;
}
tail->next=new node(data);
return;
}
int main() {

int n,data,k;
cin>>n;
node* head=NULL;
for(int i=0;i<n;i++)
{
	cin>>data;
	insert(head,data);
}
cin>>k;
node* ans=k_append(head,n,k);
print(ans);
return 0;

}

@anyamaurya

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

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.