Reverse recursively

error in the 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 *tail=head;
while(tail->next!=NULL){
tail=tail->next;
}
tail->next=new node(data);
return;
}
void buildInput(node *&head){
int data;
cin>>data;
while(data!=-1){
insertAtTail(head,data);
cin>>data;
}
}
void reverseIterative(node *&head){
node * curr=head;
node * n;
node * prev =NULL;
while(curr!=NULL){
//store the next list
n=curr->next;
//make current node point to previous
curr->next=prev;
//update
prev=curr;
curr=n;
}
head = prev;
}

node* reverseRecursive(node *head{
if(head->next==NULL||head==NULL){
return head;
}
node *smallHead= reverseRecursive(head->next);
node * curr=head;
curr->next->next=curr;
curr->next=NULL;
return smallHead;
}

void print(node *head){
//node *temp=head;
while(head!=NULL){
cout<data;
head=head->next;
}
}
int main(){
node *head=NULL;
buildInput(head);
head = reverseRecursive(head);
print(head);
return 0;}

@ayu2321
the recursive reverse function seems quite fine. There might be error in any other part of the code. Can you tell me what error are you facing? Also can you post your code in coding blocks IDE link?

i m getting the same list that i entered as the output

Okay, let me check, can you post your code in coding blocks IDE link?

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.