根据pos获取元素
获取元素,而不是结点
获取链表元素思路:
参数:list,pos
参数权限判断: pos>List.size||pos<=0
抛出异常 终止掉
获取元素的结点 current;
找到第 pos 位置的元素
返回元素的本身
获取链表元素对应的代码
const ElemType& GetLinkListElem(const LinkList& List, int pos){
if (pos>List.size||pos<=0){
throw out_of_range("pos>List.size||pos<=0 Do not exceed the range ");
}
const LinkNode* curent = List.list;
for (int i = 0; i <pos; i++){
curent = curent->next;
}
return curent->value;
}