Link-list k append

#include
using namespace std;
class node{
public:
int data;
node* next;
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 buildlist(node
&head,int n){
int data;
int count=0;
while(count<n){
cin>>data;
insertattail(head,data);
count++;
} return;
}
void printlist(nodehead){
while(head!=NULL){
cout<data<<" ";
head=head->next;
}
cout<<endl;
}
int length(node
head){
int len=0;
while(head!=NULL){
head=head->next;
len+=1;
}
return len;
}

node* append(nodehead,int n,int k){
node
c=head;
node*p=head;
int count=0;
while(count<n-k){
p=p->next;
c=c->next;
}

// int m=length©;
nodetemp=c;
while(temp->next!=NULL){
temp=temp->next;
}
temp->next=head;
head=p->next;
p->next=NULL;
return head;
}
int main() {
int n;
cin>>n;
node
head=NULL;
buildlist(head,n);
// printlist(head);
int k;
cin>>k;
head=append(head,n,k);
printlist(head);
}
whats wrong in this code?

please refer to the KAppend() function
i have added proper comments for better understadning

1 Like

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.