문제

In a Scala project, I need a simple, mutable queue data structure where I can append items on one end and take out items on the other (i.e. FIFO). Now, I'm not sure whether I should use the plain old LinkedList from Java, or Scala's DoubleLinkedList. What are the relative advantages of these two? Should I always prefer the DoubleLinkedList, or is there any good reason to use LinkedList? Also, are there any other options worth considering?

도움이 되었습니까?

해결책

As for other options, consider using a scala.collection.mutable.Queue. There is even an immutable version: scala.collection.immutable.Queue.

A quote from the doc:

Queue objects implement data structures that allow to insert and retrieve elements in a first-in-first-out (FIFO) manner.

so if your intention is to have a FIFO/Queue, the class name Queue could be easier to read/maintain than any LinkedList

다른 팁

If you want to interface with Java code it is perhaps an advantage to use the LinkedList.

Else if you only have scala code then go for the DoubleLinkedList as it has many advantages in scala.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top