6-4 链式表的按序号查找 (10 分)

题目地址:https://pintia.cn/problem-sets/15/problems/727

题目输入最后一个-1代表输入结束,所以查询位置6的结果是NA

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
原文地址:https://www.cnblogs.com/mile-star/p/11457611.html