An algorithm to compute the Stanley depth of monomial ideals