标签:i++ 结构 element next list 倒数 pre log http
ElementType Find( List L, int m ) { List p1 = L; List p2 = L; List pLast = NULL; int c = 0; while (p1) { if (c == m) { p2 = L; } p1 = p1->Next; p2 = p2->Next; pLast = p2; c++; } if (c > m) return pLast->Data;
else return -1; }
ElementType Find( List L, int m ) { List pCurrent = L; List pFind = L; for (int i =0; i<m;i++) if (pCurrent) pCurrent = pCurrent->Next; else return -1; while (pCurrent) { pFind = pFind->Next; pCurrent = pCurrent->Next; } return pFind->Data; }
浙大数据结构第二版 习题3.5 求链表的倒数第m个元素 答案错了一点
标签:i++ 结构 element next list 倒数 pre log http
原文地址:http://www.cnblogs.com/zangkuo/p/6209669.html