node* get_Mth_from_end(node* head, int m)
{
int pos = 0;
node** node_array = new node*[m + 1];
node_array[0] = head;
while (node_array[(pos + 1) % (m + 1)] = node_array[pos % (m + 1)]->next)
pos++;
if (pos < m)
{
delete[] node_array;
return NULL;
}
pos = pos - m;
if (pos < 0)
pos = pos + m + 1;
node* retval = node_array[pos];
delete[] node_array;
return retval;
}
int getNumNodesAfter(Node *node){
if( node->next == NULL ){
return 0;
}else{
return getNumNodesAfter(node->next) + 1;
}
}
for (n=0, front = 0; p[front] != end; ++n, ++p[front]) {
for (j = 0; j < m; ++j)
if (n % j = 0)
++ front
front = front % m
}
front = (front-1) % m
for (j = M; j < n-2^m - (n mod 2^m); ++j)
++p[front]
FindNFromEnd(head, n)
counter = 0;
first = head
firstplusn = head
while (head.next != null)
counter++
head = head.next
if counter == n
first = firstplusn
firstplusn = head
counter = 0
while counter < n
counter++
first = first.next
return first
0 1 2 3 4 5 6 7
1 FNH
2 FN H
3 FN H
1 F NH
2 F N H
3 F N H
1 F N H
2 F N H
---
3 [F]