In this paper, a two-sided single-detour untangling problem with capacity constraints can be firstly formulated. Furthermore, based on the optimality of hierarchical bubble sorting, an O(n2) algorithm is proposed to solve the two-sided untangling problem