code from <<data structure>>(Yan Weimin)