Thread: function help

  1. #1
    help me
    Guest

    Unhappy function help

    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;
    }

  2. #2
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807
    when posting code, use use code-tags .

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM