Also, it looks like it would be possible to write this function in a purely functional style with both queue and acc being lists, right?