When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
1 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
i == size() is already out of bounds. Consider a list with 0 elements and someone requesting element 0.
You should also try to post a complete example. There is a chance it's an error in some add function you're not showing.
Also use a debugger, it should be able to show you the state of the list.
i throw an exception for that!? there is no problem in add function. I also did a get_At using next pointer that works properly. I'll leave it here ```
template<class T>
T DoubleLinkedList<T>::get_at(int i) const {
if(i < 0 || i >= size())
throw invalid_argument("index out of range");
Node<T>* crt = first;
int noE = 0;
while (noE < i){
crt = crt->next;
noE++;
}
return crt->info;}
@gaunt dragon do you know what the problem might be?
Oh, right. Apparently I didn't pay attention.
someone has corrupted your list with some function, iterating over it and accessing nodes causes trying to read the corrupted nodes, leading to crashes
the get_at function is legit
Done! Thank you!
@gusty willow Has your question been resolved? If so, run !solved :)
!solved
Thank you and let us know if you have any more questions!
This thread is now set to auto-hide after an hour of inactivity