Not able to understand the error

#include
using namespace std;
class node{
public:
int data;
node* next;
};
void insert(node** head,int data){
if(head==NULL){
head=new node(data);
return;
}
node* tail=head;
while(tail->next !=NULL){
tail=tail->next;
tail->next=new node(data);
return;
}
}
node* reverse(node* head,int k){
node* current=head;
node* next=NULL;
node* prev=NULL;
int count=0;
while(current!=NULL &&count<k){
next=current->next;
current->next=prev;
prev=current;
current=next;
count++;
}
if(next!=NULL){
head->next=reverse(head,k);
}
return prev;
}
void print(node* head){
node* temp=head;
while(temp->next!=NULL){
cout<<temp<<" ";
temp=temp->next;
}return;
}
int main() {
int n,k;
cin>>n>>k;
node* head=NULL;
for(int f=1;f<=n;f++){
int data;
cin>>data;
insert(&head,data);
}
head=reverse(head,k);
print(head);
return 0;
}

@toshitvarshney11 hey do k=k%length of linked list in starting,rets your logic is correct.

i think i having problem in taking input as a linked list please help me with that

@toshitvarshney11 hey check out this code for input of linked list:

1 Like

thanks sir it worked

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.