1 /****************************************
2 > File Name:test.c
3 > Author:xiaoxiaohui
4 > mail:1924224891@qq.com
5 > Created Time:2016年05月26日 星期四 19时49分45秒
6 ****************************************/
7
8
9 //当用一个指针遍历链表不能解决问题时,可以尝试用两个指针来做
10 //一个指针走的快一点,一个指针走的慢一点
11 // 可以简言之为 《快慢指针》 哈哈哈............
12
13
14 #include<stdio.h>
15
16
17 ListNode* FindNode(ListNode* head, int k)
18 {
19 if(head == NULL || k <= 0)
20 {
21 printf("parameter is error!\n");
22 return NULL;
23 }
24
25 ListNode* fitst = head;
26 ListNode* second = head;
27
28 for(int i = 0; i < k - 1; i++)
29 {
30 if(first->_next == NULL)
31 {
32 printf("the K is bigger than the list len!\n");
33 return NULL;
34 }
35 first = first->_next;
36 }
37
38 while(first->_next != NULL)
39 {
40 first = first->_next;
41 second = second->_next;
42 }
43
44 return second;
45 }
转载于:https://blog.51cto.com/10704527/1783646