I wanted to attach two linked lists using concat()
function,
but I have noticed that concat()
returns the last value of head
although there is no return
at the end of concat()
!
what I mean is when I send the heads of the following two linked lists to concat()
: 1->2->3->4
and 5->6->7
I do expect an ouput like this :1->2->3->4->5->6->7
,but instead I get a linked list of this form 4->5->6->7
!
can I know where's the problem? thanks in advance
typedef struct node{
int data;
struct node* next;
}list;
list* Concat(list* head,list* P)
{
if(!head) return P;
if(!P) return head;
while(head->next) head=head->next;
head->next=P;
}