April 18, 2015
GRK
Problem Statement
You're given the pointer to the head node of a linked list and you need to print all its elements in reverse order from tail to head, one element per line. The head pointer may be null meaning that the list is empty - in that case, don't print anything!
Soruce code:
/*
Print elements of a linked list in reverse order as standard output
head pointer could be NULL as well for empty list
Node is defined as
struct Node
{
int data;
struct Node *next;
}
*/
void ReversePrint(Node *head)
{
// This is a "method-only" submission.
// You only need to complete this method.
int a[100],i=0;
while(head!=NULL){
a[i] = head->data;
i++;
head = head->next;
}
for(int j = i-1;j>=0;j--){
cout<<a[j]<<endl;
}
}
This comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteMany printers have a feature that reverses the output. The problem is there doesn’t seem to be a consistent name for this feature.Some names are given like flip horizontal
ReplyDelete,mirror image,reverse or emulsion down.The given source code is very helpful in creating a back print.
I like your professional advice! you are an example for me. keep going! follow writing essays custom and improve youself as well as your site!
ReplyDeleteu did well but linkedlist means we should allocate memory in dynamic location but u used arrays ,what happen if give more than 100 numbers??
ReplyDeleteBlogs Comments
ReplyDelete