0

また助けが必要です。このコードの何が問題なのかわかりません。誰か助けてもらえますか?

def moveTower(n: Int, source: Stack[Int], sink: Stack[Int], workspace: Stack[Int]):     Stack[Int] = {
    if (n == 1) {
      sink.push(source.pop.##)
    } else {
      moveTower(n - 1, source, workspace, sink)
      sink.push(source.pop.##)
      moveTower(n - 1, workspace, sink, source)
    }
  }

  var source = Stack[Int](5, 4, 3, 2, 1)
  var sink = Stack[Int]()
  var workspace = Stack[Int]()
  moveTower(source.length.toInt, source, sink, workspace)
  println(source, sink, workspace)
4

1 に答える 1