To find the Nth node from the end of the linked list

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kalkisai
    New Member
    • Dec 2007
    • 1

    To find the Nth node from the end of the linked list

    void Nth_Node_End(No de First, int N)
    {
    Node Cur_Node, N_node;
    Cur_Node = First;
    N_node = First;
    while(Cur_Node)
    {
    for(i = 0; i < N; i++)
    {
    Cur_Node = Cur_Node->Next;
    }
    if(Cur_Node == NULL)
    break;
    else
    {
    Cur_Node = N_node->Next;
    N_node = N_node->Next;
    }
    }
    Printf("The Nth node is %x and its value = %d\n", N_node,N_node->Value);
    }
    Assuming the Linked list is not empty
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    Did you have a question on this code, or did you just want to post your function?

    Comment

    Working...