A Lanczos type algorithm for inverse Sturm-Liouville problems