# Why doesn't this work recursively?

Below is a program in Scala.

```def range(low : Int, high : Int) : List[Int] = {
var result : List[Int] = Nil
result = rangerec(root, result, low, high)
result
}

private def rangerec(r : Node, l : List[Int], low : Int, high :Int) : List[Int] = {
var resultList : List[Int] = List()
if(r.left != null) {
rangerec(r.left, resultList, low, high)
} else if(r.right != null) {
rangerec(r.right, resultList, low, high)
} else {
if(r.key >= low && r.key <= high) {
resultList = resultList ::: List(r.key)
resultList
}
}
resultList
}
```

I made range method in my binary search tree, implementing in-order traversal algorithm. So it has to work recursively, but it doesn't print anything, List(). How to fix my algorithm? or edit my code?

I don't know scala, but you need to use list l passed as a parameter into recursive function and use output from rangerec function.

```private def rangerec(r : Node, l : List[Int], low : Int, high :Int) : List[Int] = {
var resultList : List[Int] = l
if(r.left != null) {
resultList = rangerec(r.left, l, low, high)
} else if(r.right != null) {
resultList = rangerec(r.right, l, low, high)
} else {
if(r.key >= low && r.key <= high) {
resultList = l ::: List(r.key)
}
}
resultList
}
```