wood burning stoves
The moose likes Java in General and the fly likes Creating Linked List Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Creating Linked List" Watch "Creating Linked List" New topic

Creating Linked List

deshdeep divakar
Ranch Hand

Joined: Apr 19, 2004
Posts: 91
Can anybody tell me how can I implement Linked List without
using util class

"Do not be afraid of going slow, be afraid of standing still"
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Sorry this is not in the scope of SCJP so it's now here.
[ November 02, 2004: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
A singly linked list has a pointer from each element to the next. Let's make a Node class that holds a pointer to the next Node and some object that you put there:

We could build a list like this (just typing, not compiling or testing!)

When I first started making these things, I had to draw each new node on a piece of paper and draw arrows for the "next" pointers. After a while it made sense.

For more fun, think about removing a node in the middle, or the first node. If you really think that was fun, come back and we'll talk about doubly linked lists!

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
I agree. Here's the link: http://aspose.com/file-tools
subject: Creating Linked List
It's not a secret anymore!