Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Creating Linked List  RSS feed

 
deshdeep divakar
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Can anybody tell me how can I implement Linked List without
using util class
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry this is not in the scope of SCJP so it's now here.
[ November 02, 2004: Message edited by: Barry Gaunt ]
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!