in function insertAtTail why it is written (tail->next!=NULL) why we can’t simply write tail!=NULL as before already we pointed node *tail=head
Linked list insertion at end
hello @shubhangis248
to insert at end we need to reach to the end node of current existing list right?
and how we can identify end node ?
value of next of end node will be NULL right?
i.e end_node->next will be NULL.
thats is the reason why we put tail->next!=NULL condition in the while condition,
the while loop will break when we will have tail->next==NULL
which means tail is the end node of current list
if we already declared tail as of type node it will have two types int data and next node as per class so why to declare tail->next particularly why not just tail!=NULL
if we will use this condition then our loop will stop when tail will become NULL right?
but what we want ? we want last node of the list.
what unique property last node has?
there is no node next to last node right?
that means tail->next is NULL that is the reason we r using tail->next!= NULL in place of tail!=NULL
If that’s the case,then while printing linked list why we declare head!=NULL not head->next!=NULL in that case also,we are going till end of linked list
1->2->3->NULL
just do a dry run u will get difference
understood what u r saying