#include
using namespace std;
class node{
public:
int data;
nodenext;
node(int d)
{
data=d;
next=NULL;
}
};
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 print(nodehead)
{
while(head!=NULL)
{
cout<data<<" ";
head=head->next;
}
cout<<endl;
}
int length(nodehead)
{
int len=0;
while(head!=NULL)
{
head=head->next;
len+=1;
}
return len;
}
void middle(node&head,int pos)
{
if(head==NULL|| head->next==NULL)
{
return;
}
nodefast=head;
nodeprev=head;
nodep=head;
int jump=1;
while(jump<=length(head)-pos)
{ prev=fast;
fast=fast->next;
jump+=1;
}
prev->next=NULL;
nodetemp=fast;
int count=0;
while(temp->next!=NULL)
{ count++;
temp=temp->next;
}
temp->next=head;
print(fast);
//print(head);
//print(head);
}
int main() {
int n;
cin>>n;
int arr[n];
node*head=NULL;
for(int i=0;i<n;i++)
{
cin>>arr[i];
insertattail(head,arr[i]);
}
int pos;
cin>>pos;
middle(head,pos);
return 0;
}
I am getting run time error in this code. plz resolve it
@Kunalgoyal you need to take care of cases where k > n. You can do so by adding this line before calling the function.

Please mark your doubt as resolved.
one test case is still showing run time error.
k means position . na
if pos=0 then return head. is it right
okay. got it thanks.
