How does computer read linked list
first thanks JosAH Junky liyuyu_852000 for answering my question on accessing linked list elements.
Now I am having an algorithm question. I have a linked list for more than 1000 elements (Strings). I want to compare them one by one, with existing strings.
I understand that computer accesses linked list by looking a the first element and follows the pointer one by one, till the desired stack.
I remember taking Operating Systems class and it says people design the OS in sort of the way that it executes the fastest on the way it is mostly used. My question is, would OS / Java Editor save the position of the last accessed element? for example, I wrote a for loop,
Code:
// list is a LinkedList. sentence is an array.
for(i = 0; i < list.size(); i++){
for (j = 0; j < number_of_sentences; j++){
if(sentence[j].equals((String) list.get(i))){
match ++ ;
}
}
}
does computer remember the element of the list at i's position, so when it reads (i+1)'s element, it won't start from the beginning?