6-4 chain by serial number lookup table (10 points)

Topic Address: https://pintia.cn/problem-sets/15/problems/727

Enter the last title -1 representative of the input end, so that the position of the query result is NA 6

ElementType FindKth(List L, int K) {
    List p = L;
    int cnt = 0;
    while(p) {
        cnt++;
        if(cnt == K) {
            return p->Data;
        }
        p = p->Next;
    }
    return ERROR;
}
View Code

 

Guess you like

Origin www.cnblogs.com/mile-star/p/11457611.html