Two-way bubble sorting method