template <typename Sequence> void bubbleSort1(Sequence& S) { // bubble-sort using ranks int n = S.size(); for (int i = 0; i < n; i++) // i-th pass for (int j = 1; j < n-i; j++) if ( S.elemAtRank(j-1) > S.elemAtRank(j) ) S.swapElements(S.atRank(j-1), S.atRank(j)); } template <typename Sequence> void bubbleSort2(Sequence& S) { // bubble-sort using positions typedef typename Sequence::Position Position; int n = S.size(); for (int i = 0; i < n; i++) { // i-th pass Position prec = S.first(); for (int j = 1; j < n-i; j++) { Position succ = S.after(prec); if ( prec.element() > succ.element() ) S.swapElements(prec, succ); prec = succ; } } }