*node *middle(node *head)
{
     node *mid;

     mid = head;
     for(int i = 2;head!=NULL;head=head->next,i++)
     {
             (i%2==1) mid = mid->next;
     }
     return mid;
}*

To find 1/3rd of a list, change (i%2==1) to (i%3==1)....i.e. nth node can be
found (i%n==1) (make sure n<=no. of nodes)

Now to find 3/4th of a node, we can do following

initial call *threefourth(head,3,4);*

*node *threefourth(node *head,int m,int n)
{
     node *mid,*p;
     p = head->next;
     mid = head;
     while(m)
     {
             for(int i = 2;p!=NULL;p=p->next,i++)
             {
                     (i%n==1) mid = mid->next;
             }
             m--;
             if(m==0) return mid;
             else
                 mid = mid->next;
             p = head->next;

     }
}*



-- 
*Piyush Sinha*
*IIIT, Allahabad*
*+91-7483122727*
* <https://www.facebook.com/profile.php?id=100000655377926> "NEVER SAY
NEVER"
*

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to