I created a queue in which we can perform Enqueue, Dequeue and Traversing in Scala.

class Queue[+A](list:List[A]) {
  def enqueue[B>:A](x:B):Queue[B]= new Queue[B](list :+ x)
  def dequeue[B>:A]:Queue[B] = new Queue[B](list.tail)
  def head = list.head
  def tail = list.tail

Please review this code and make suggestions.

  • \$\begingroup\$ Inside the Scala language source code, you can see how they implemented it. It can give you hints on how to refactor your class. \$\endgroup\$ – meucaa May 30 '16 at 12:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.