I have a linked list and want to be able to access any element in the list by inputting an int. I have this code so far and want to know if i am going about it in the right manner.
1 2 3 4 5 6 7 8 9 10 11 12
ListElement *List::GetElement(unsignedint r){
ListElement *current;
unsignedint count = 0;
if (r == count){
while (r!=count){
count++;
current = current->next;
}
return current;
}
}