I m getting run time error.Could u pls help me find my mistake

#include
using namespace std;
class node{
public:
int data;
node* next;
node(int d)
{
data=d;
}
};
int length(nodehead)
{
int len=0;
while(head!=NULL)
{
head=head->next;
len++;
}
return len;
}
node
findK(nodehead,int k)
{
node
fast=head;
nodeslow=head;
while(k–)
{
fast=fast->next;
}
while(fast!=NULL)
{
fast=fast->next;
slow=slow->next;
}
return slow;
}
void insertAtTail(node
&head,int data)
{
if(head==NULL)
{
head=new node(data);
return;
}
nodetail=head;
while(tail->next!=NULL)
{
tail=tail->next;
}
tail->next=new node(data);
return;
}
void buildList(node
&head)
{
int n;
cin>>n;
while(n–)
{
int data;
cin>>data;
insertAtTail(head,data);
}
}
void print(nodehead)
{
while(head!=NULL)
{
cout<data<<" ";
head=head->next;
}
}
int main() {
node
head=NULL;
buildList(head);
int k;
cin>>k;
int n=length(head);
nodec=findK(head,k);
node
current=head;
nodepre=head;
while(current!=c)
{
current=current->next;
pre=pre->next;
}
pre->next=NULL;
node
temp=c;
while(temp->next!=NULL)
{
temp=temp->next;
}
temp->next=head;
print(head);
return 0;
}

Harsh, there are few changes you need to make in your findk function as,
node *append_nodes(node *head, int k)
{
node *slow = head;
node *fast = head;
node *oldHead=head;
for(int i=0; i<k && fast->next!=NULL; i++)
{
fast = fast ->next;
}
while(fast->next !=NULL && fast !=NULL)
{
fast = fast->next;
slow = slow->next;
}
node *newHead=slow->next;
slow->next = NULL;
fast->next = oldHead;
return newHead;
}

This is how you need to follow up runner approach in your function…

Still getting error.Can u please debug my code.

hey @Hk199977 can you give me your final code on the ide.codingblocks.com so that i can have a look and help you out

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.