I need implement an very fast linked list. Can you help me?
3 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Wednesday, October 9, 2002 04:58 AM

Hello, I need to store some data in a linked list. At any time I can remove any element at any position into the list or can insert a new one. The algorithm used to decide what is the element that must be removed requires to looking over each element on the list to see if it is the one that must be removed. This problem is very easy to solve in C if we use pointers and a linked list. Besides the C solution is very fast. But in Java there are not pointers. A solution could be made by means of an array and several additional control variables, but when an element is removed, it is necessary to move in one position the rest ones (the rest of the elements must keep its original order, as in a queue), and th   More>>

Hello,

I need to store some data in a linked list. At any time I can remove any element at any position into the list or can insert a new one. The algorithm used to decide what is the element that must be removed requires to looking over each element on the list to see if it is the one that must be removed.

This problem is very easy to solve in C if we use pointers and a linked list. Besides the C solution is very fast.

But in Java there are not pointers. A solution could be made by means of an array and several additional control variables, but when an element is removed, it is necessary to move in one position the rest ones (the rest of the elements must keep its original order, as in a queue), and this needs a lot of time.

Can you suggest me how can I implement a double linked list in java?


Many thanks

José Fernández

   <<Less

Re: I need implement an very fast linked list. Can you help me?

Posted By:   Jeanne_Boyarsky  
Posted On:   Wednesday, October 9, 2002 05:42 PM

If you want a singly linked list, you can use java.util.LinkedList as suggested. However if you want a double linked list, you need to write it yourself. It is very similar to how you would do it in C.
You would have a node class:

public class Node {
private Object data;
private Node before, after;
}

Then you would have another class for the actual linked list with the methods as they would be in C.

Re: I need implement an very fast linked list. Can you help me?

Posted By:   Lasse_Koskela  
Posted On:   Wednesday, October 9, 2002 07:46 AM

Actually, Java does have pointers. They have just been abstracted into object references...

Re: I need implement an very fast linked list. Can you help me?

Posted By:   Anonymous  
Posted On:   Wednesday, October 9, 2002 05:53 AM

Look at the java.util.LinkedList...
About | Sitemap | Contact