Whats wrong in this cide ..i m trying LL-K REVERSE PROBLEM

#include<bits/stdc++.h>
using namespace std;
class node{
public:
int data;
nodenext;
node(int d){
data=d;
next=NULL;
}
};
void insertathead(node
&head,int data){
noden=new node(data);
n->next=head;
head=n;
}
void insertatend(node
&head,int data){
if(head==NULL){
insertathead(head,data);
}
nodetemp=head;
while(temp->next!=NULL){
temp=temp->next;
}
node
n=new node(data);
temp->next=n;
}
void buildlist(node*&head,int n){

int data;
cin>>data;
while(n--){
    insertatend(head,data);
    cin>>data;
}

}
void reverselist(node*&head,int k,int n){
nodecurrent=head;
node
numb;
nodeprev=head;
node
temp=head;

for(int i=0;i<n;i=i+k){
int jump=0;
while(jump!=k | current->next!= NULL){
temp=temp->next;
jump=jump+1;
}
current->next=numb;
temp->next=current;
numb->next=prev;
prev=numb;
}
}

void print(node*head){
while(head!=NULL){
cout<data<<"->";
head=head->next;
}
}

int main(){
node*head=NULL;
int n,k;
cin>>n>>k;
buildlist(head,n);
reverselist(head,k,n);
print(head);
return 0;
}

Hey @gabbar_2229
Your code has some compilation and logical errors.
Firstly you need to correct your print and buildlist functions

  1. in print function, you need to write
    cout << head->data << “->”
    instead of
    cout << data << “->”
    so print function would go like:

void print(node*head){
while(head!=NULL){
cout<data<<"->";
head=head->next;
}
}

  1. in the buildlist function, first you need to take input n times,
    build function would be like:
    void buildlist(node*&head,int n){
    int d;
    while(n–){
    cin>>d;
    insertatend(head,d);
    }
    }

  2. in the insertatend function, you need to write else, after your if, coz you have to perform the lower steps only if head is not NULL

so the insertatend function would be like:

void insertatend(node*&head,int data){
if(head==NULL){
insertathead(head,data);
}
else{
node *temp=head;
while(temp->next!=NULL){
temp=temp->next;
}
node*n=new node(data);
temp->next=n;
}
}

  1. also your code for reverse has error, you need to write the linked list reversal code for every k elements, that is inside the inner while loop, you’ve to write the code for reversal of those k elements, so you need to correct your reverselist function also.

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.