I am starting a series of posts that are targeted towards Data Structures that I had been wanting to write for a long time. They are simple code snippets. For many this might not be useful but for some, it might be. So here we go, the first one is to print the contents of a Linked list in reverse order
void displayReverse(node* head){
if(head==NULL){
cout<<"Nothing to display"<<endl;
}
else
{
if(head->next != NULL){
displayReverse(head->next);
}
else
{
cout<<head->data<<endl;
return;
}
cout<<head->data<<endl;
}
}
Advertisement
Discussion
No comments yet.