3
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\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
    Commented May 30, 2016 at 12:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.