typedef struct list_node{
int i;
list_node *next;
}LIST_NODE;
LIST_NODE *find_node(LIST_NODE *head, int k)
{
LIST_NODE *p1 = head;
int count = 0;
while(p1 && count++ < k)
p1 = p1->next;
if (!p1)
{
return NULL;
}
LIST_NODE *p2 = head;
while(p1 && p1->next)
{
p1 = p1->next;
p2 = p2->next;
}
return p2;
}
LIST_NODE *find_node(LIST_NODE *head)
{
LIST_NODE *p1, *p2;
if (head == NULL || head->next == NULL)
{
return head;
}
p1 = head;
p2 = head->next;
while(p2->next && p2->next->next)
{
p2 = p2->next->next;
p1 = p1->next;
}
if (p2->next)
{
return p1->next;
}
return p1;
}
int _tmain(int argc, _TCHAR* argv[])
{
LIST_NODE *head = new LIST_NODE;
head->i = 0;
LIST_NODE *temp = head;
for (int j = 0; j < 11; j++)
{
LIST_NODE *p = new LIST_NODE;
p->i = ++j;
temp->next = p;
temp = p;
}
temp->next = NULL;
for (LIST_NODE *temp = head; temp; temp = temp->next)
{
cout << " " << temp->i << " ";
}
LIST_NODE *temp2 = find_node(head);
if(temp2)
cout << "/n" << temp2->i << endl;
system("pause");
return 0;
}