Hello,
I am working on my IB computer science coursework and I'm a bit conceptually confused at the moment.
I am creating a program in Java where the user inputs Strings which are stored in a linkedlist. I understand the general theory behind the linkedlist (data gets passed into nodes which point to other nodes until it gets to the end ect)
However, I have coded a linkedlist (or what I believe to be one) and I'm confused how to retrieve data. From what I understand the nodes are stored in RAM, but how do I acces the individual nodes? (I have an indexed linkedlist).
Am I missing something rather large here? I feel that I am...
Thank you.
Trouble with LinkedList
Page 1 of 13 Replies - 1086 Views - Last Post: 05 January 2012 - 08:43 AM
Topic Sponsor:
Replies To: Trouble with LinkedList
#2
Re: Trouble with LinkedList
Posted 05 January 2012 - 08:33 AM
Unlike arrays, nodes in linked lists are not stored sequentially in the memory, just a bunch of nodes scattered around with each node having a pointer to the next node. So the only way to access a certain node in the linked list is to iterate through all the nodes starting with the head of the list until you reach the node you are looking for. If your linked list is indexed then you may use it as an array and just pass the index of the node you want to access (see ArrayList in Java). Hope this answers your question.
#3
Re: Trouble with LinkedList
Posted 05 January 2012 - 08:41 AM
mostyfriedman, on 05 January 2012 - 08:33 AM, said:
Unlike arrays, nodes in linked lists are not stored sequentially in the memory, just a bunch of nodes scattered around with each node having a pointer to the next node. So the only way to access a certain node in the linked list is to iterate through all the nodes starting with the head of the list until you reach the node you are looking for. If your linked list is indexed then you may use it as an array and just pass the index of the node you want to access (see ArrayList in Java). Hope this answers your question.
Thank you for the help (: that clears it up quite a bit!
#4
Re: Trouble with LinkedList
Posted 05 January 2012 - 08:43 AM
Page 1 of 1
|
|

New Topic/Question
Reply


MultiQuote





|