my program is showing srror in some test case what is the problem…
my code:
#include
using namespace std;
class node
{
public:
int data;
node* next;
//constructor
node(int d){
data=d;
next=NULL;
}
};
void insertAtTail(node*&head,int data){
if(head==NULL){
head=new node(data);
return;
}
node* temp=head;
while(temp->next!=NULL){
temp=temp->next;
}
temp->next=new node(data);
return;
}
node* buildlist(node*& head,int n){
while(n–)
{
int data;
cin>>data;
insertAtTail(head,data);
}
}
node* append(node*&head,int k){
node* fast=head;
node* slow=head;
for(int i=1;i<=k;i++){
fast=fast->next;
}
while(fast->next!=NULL){
fast=fast->next;
slow=slow->next;
}
nodec=slow->next;
slow->next=NULL;
fast->next=head;
return c;
}
void print(node head){
node* temp=head;
while(temp!=NULL){
cout<data<<" ";
temp=temp->next;
}
}
int main() {
int n;
cin>>n;
node* head=NULL;
buildlist(head,n);
int k;
cin>>k;
head=append(head,k);
print(head);
}