Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
ListNode  FindnthToLast(int  n)  {

    	if (n <1 || headNode == null)
    	  return null;

    	ListNode pntr1 = headNode, pntr2 = headNode;

    	//advance pntr2 by n-1 nodes;    
    	for  (int  i  =  0;  i  <  n  - 1;  ++i)  {  

    	if  (pntr2  ==  null)  {
    	  return null; 
    	  }

    	else //go to the next node
    	   pntr2 = pntr2.getNext();

    	}


    	while(pntr2.getNext() != null)
    	{
    	  pntr1 = pntr1.getNext();
    	  pntr2 = pntr2.getNext();
    	}

    	return pntr1;

    	}
Posted
Updated 9-Jul-13 22:29pm
v2

1 solution

Hi,

Here you find an explanation on how to calculate the Time Complexity for a function:
http://blogs.msdn.com/b/nmallick/archive/2010/03/30/how-to-calculate-time-complexity-for-a-given-algorithm.aspx[^]
 
Share this answer
 
Comments
Garth J Lancaster 10-Jul-13 4:38am    
That was a great link !
Thomas Daniels 10-Jul-13 4:40am    
Thank you!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900