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; }
时间: 2024-10-26 04:07:29