i have to implement the following function and i have already implemented the insertAtTail() function but not getting the below one right "The insertAfter().plz help!
#define ElementType int
#define NodePtr struct Node*
typedef NodePtr List;
void insertAfter(List l, ElementType x , ElementType y)
{
/*
This function should create a new node after the node containing x and insert y in that node. If x is not present in the list, y should be inserted at the tail
*/
NodePtr temp;
NodePtr temp1;
temp1=l;
if(temp1->next==NULL)
insertAtTail(l,y);
else
{
while(temp1->next->data != x && temp1->next != NULL)
temp1=temp1->next;
if(temp1->next == NULL)
insertAtTail(l,y);
else if( temp1->next->data == x )
{
temp=createNewNode(y);
temp1=temp1->next;// temp1=x
temp->next=temp1->next;//
temp1->next=temp;
}
}
}
void insertAtTail(List l, ElementType x)
{
NodePtr temp;
NodePtr temp1;
temp1=l;
temp=createNewNode(x);
while (temp1->next != NULL)
temp1=temp1->next;
temp1->next=temp;
temp->next=NULL;
}