Solved

LinkedList data structure ... also synchronized?

Posted on 2006-06-13
7
339 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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:mayankeagle
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now