• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Implement linked list in java

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Can anyone tell me how to implement linked list in java without using JAVA API's.

Regards
 
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Nilesh! you want the entire code?? i am sure you dont want the entire code, only a starting point, right?

since you know linked lists, i will not talk on that. the key concept while implementing linked lists in Java is that objects are always passed by reference.

here is a sample implementation. this is bare bones implementation, but i think sufficient to get you started.

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Neeraj outlined the basic idea, but here are a couple of details you might keep in mind.

1) Java's garbage collection features make removing a Node from a linked list easier, as you don't have to explicitly set a pointer to a Node to null.

2) When implementing a remove(Object key) method for your own linked list, you'll start to appreciate why Java included Iterator interfaces. You might want to implement your own iterator() function in your linked list that returns a special implementation of Iterator to remove Nodes in your linked list. That will make your code more readable and more OO.
 
reply
    Bookmark Topic Watch Topic
  • New Topic