I want to print the reverse of a linked list. I am doing it by recursion. But while calling read(temp) in function read, it gives a BUS ERROR.
Any reasons why is this happening ??
#include <iostream>
using namespace std;
struct node
{
int info;
node *next;
};
void read(node *start)
{
node *temp = start->next;
if(start == NULL)
cout<<start->info<<"\n";
else
{
read(temp);
cout<<start->info<<"\n";
}
}
int main()
{
node *start = NULL;
for(int i=0;i<5;i++)
{
node *temp = new node;
temp->info=i;
temp->next=NULL;
if(start == NULL)
start = temp;
else
{
temp->next = start;
start = temp;
}
}
read(start);
}