3 Replies - 1086 Views - Last Post: 05 January 2012 - 08:43 AM

Topic Sponsor:

#1 colourfulbananas  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 05-January 12

Trouble with LinkedList

Posted 05 January 2012 - 08:25 AM

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.

Is This A Good Question/Topic? 0
  • +

Replies To: Trouble with LinkedList

#2 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 640
  • View blog
  • Posts: 4,287
  • Joined: 24-October 08

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.
Was This Post Helpful? 2
  • +
  • -

#3 colourfulbananas  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 05-January 12

Re: Trouble with LinkedList

Posted 05 January 2012 - 08:41 AM

View Postmostyfriedman, 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! :D
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is online

  • No Sugar Coding Here!
  • member icon

Reputation: 4678
  • View blog
  • Posts: 20,353
  • Joined: 23-August 08

Re: Trouble with LinkedList

Posted 05 January 2012 - 08:43 AM

This is a good look at Linked Lists as well.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1