Linked list

Hello, I'm finding linked list hard to learn, I need ---- understanding it.
Think of some kind of object. Could be anything.

Now think of lots of them, all over the place.

Pick one up. Its the object, as you were thinking of, but it's got one more thing on it. A pointer. That pointer points to another of those objects. So you go and pick that one up. That one has a pointer on it. A pointer to some other object. They all have a pointer on them, pointing to another object.

That's a linked list. What if the last one points back at the first one? It's a circular linked list.
Last edited on
I think of it as trains. The first pointer points to the engine that leads the rest of the rail cars. Each car holds information and connects to the one of front of it and the one behind. If you're at a train yard, you can disconnect certain cars from the rest of the train and reconnect the train after you've removed the one you didn't want. Singly linked list only allows you to move one way. Doubly allows you to move either way.

I know it sounds silly but it helped me. Good luck.
closed account (zb0S216C)
A train is a close analogy. The train is the list, each car is a node, and the link in between each car is a pointer to the next (going from the operators car to the last car at the end).

Wazzak
It looks like this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
   Head                           Tail
    |                              |
 ___V____                          |
| Node   |                         |
|        |                         |
| Data   |                         |
|        |       ________          |
| Next  =======>| Node   |         |
|________|      |        |         |
                | Data   |         |
                |        |       __V_____
                | Next  =======>| Node   |
                |________|      |        |
                                | Data   |
                                |        |
                                | Next  =======>Null
                                |________|
I know the general idea, but my problem is with the code.
That's a pretty generic question, and you have gotten pretty generic answers.

There are lots of good books on data structures and algorithms. I'm sure there are good descriptions on the web.

Start by trying to code up a list, and come back here for help when you get stuck. Without knowing what you've done so far, we really don't know how to help you.

Well start writing some code then and see how far you get.
Ok, I will try.
Topic archived. No new replies allowed.