******************reverse

what is wrong in this 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;

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

hey, it is hard to debug an unindented code, can please give the proper code through ide.codingblocks.com so that i can help u better

in your recursive reverse
replace

  1. curr->next->next=curr;
    with
  2. curr->next=curr;

…still not working


here you go, fixed it and added comments