hey guys , can't it be like this without reversing list-
int rec_iterate(Node head1,Node *head2)
{
if(head1 ==NULL ) return 1;
if(rec_iterate(head1->n,head2) == 0) return 0;
if (head1->value == (*head2)->value)
{ *head2=(*head2)->next;
return 1;
}
else return 0;
}
provided lists are of same length.
On Thu, Aug 11, 2011 at 1:30 AM, Don <[email protected]> wrote:
> Q1: The function below reverses a linked list in place. Call it on one
> of the lists, compare the resulting list to the other list. Then call
> it again to put the list back in its original order.
>
> list Reverse(list head)
> {
> list T, prv, nxt;
>
> prv = head;
> for(T = head->next; T; T = nxt)
> {
> nxt = T->next;
> T->next = prv;
> prv = T;
> T = nxt;
> }
> head->next = 0;
> return prv;
> }
>
> Q2:
> delete(node *d)
> {
> if (d->next)
> {
> node nxt = d->next;
> d->value = nxt->value;
> d->next = nxt->next;
> free nxt;
> }
> else
> {
> for(node p = head; p; p = p->next)
> if (p->next == d)
> {
> p->next = 0;
> free d;
> }
> }
> }
>
> On Aug 10, 1:14 pm, Piyush Kapoor <[email protected]> wrote:
> > Q1)Two linked Lists are given,i.e,their head pointers are given,and the
> > problem is to check if the second one is reverse of the first one.Give
> the
> > most efficient algo for it.
> > Q2)A linked list is given,and one of its nodes is given.The problem is to
> > delete the given node from the linked list.(The head node is not given).
> > (In both of the above cases,the linked lists are singly linked lists.)
> > --
> > *Regards,*
> > *Piyush Kapoor,*
> > *2nd year,CSE
> > IT-BHU*
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>
--
........................
*MOHIT VERMA*
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.