Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

LinkedList data structure ... also synchronized?

Posted on 2006-06-13
7
345 Views
Last Modified: 2010-03-31
I need to implement a linkedlist type of datastructure, where nodes are linearly ordered, nodes are inserted and removed at various positions in the list.

I began experimenting with java's LinkedList class, but it provides no method to insert a node into a list. So do I need to create a new class from scratch or can I somehow append the LinkedList class?

Am I better off implementing my own data structure?

Also there is an example of implemented linked list here:
http://examples.oreilly.com/jenut/LinkedList.java
but I don't quite understand the importance of synchronizing, can anyone give an example as to when its necessary?

Also does implementing the linkable interface do anything for the synchronization?

0
Comment
Question by:polkadot
  • 6
7 Comments
 
LVL 24

Expert Comment

by:sciuriware
ID: 16896121
If only one thread manipulates the list synchronisation is not necessary.
Otherwise, you need a Vector or must do all the synchronising yourself.

;JOOP!
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 16896128
... the latter means that all methods that may access the linked list have the keyword   synchronised.


This synchronisation costs overhead!!

;JOOP!
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 16896149
use methods like  .add(int index, E element) to add a node at a position.

;JOOP!
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 24

Accepted Solution

by:
sciuriware earned 500 total points
ID: 16896165
Find all other methods you need at http://java.sun.com/j2se/1.4.2/docs/api/java/util/LinkedList.html

;JOOP!
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16900704
>> but it provides no method to insert a node into a list.

? Meaning inserting between a list?

0
 
LVL 24

Expert Comment

by:sciuriware
ID: 16900877
I think he means at random position.

;JOOP!
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 16917942
:<)
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question