Update apply method in Queue.scala

changed apply method to be more functional style using foldleft