This is the version of Gale-Shapley stable matching algorithm (translated from the Matlab code in Menzel (2015)).
Useful links