Results 1 to 3 of 3
  1. #1
    smtwtfs is offline Member
    Join Date
    Feb 2011
    Posts
    9
    Rep Power
    0

    Default 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,
    Java 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?

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default

    Are you using the Java API LinkedList class or one you have written yourself?

    The class in the API does indeed start at head and follow the links to each node until it reaches the one you requested. If you are worried about performance when you iterate over the List then use the ListIterator class which keeps track of where in the List you are upto.

  3. #3
    smtwtfs is offline Member
    Join Date
    Feb 2011
    Posts
    9
    Rep Power
    0

    Default

    thanks, thats exactly my question! Turns out that 100-string linked list isn't that bad (i could feel the delay but still acceptable. its not a real time app anyway)

Similar Threads

  1. Replies: 4
    Last Post: 02-21-2011, 10:34 AM
  2. How to list all computer in a network?
    By CaptnCAPSLOCK in forum Networking
    Replies: 1
    Last Post: 01-24-2011, 02:12 PM
  3. List serial com ports of computer
    By mickey in forum New To Java
    Replies: 3
    Last Post: 08-06-2010, 08:47 AM
  4. Linked list inside a linked list
    By viperlasson in forum New To Java
    Replies: 5
    Last Post: 07-27-2010, 12:15 AM
  5. Linked List integer list
    By igniteflow in forum Advanced Java
    Replies: 1
    Last Post: 12-10-2008, 09:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •