Original address: bidirectional bubbling
Generally, the bubble is unidirectional, and here it is bidirectional, that is, reverse work is required.
CodeIt looks complicated. After careful consideration, we can see that it is a method of round-trip fluctuation.
The author of this Code thinks this can reduce some exchanges on the basis of bubbling (I don't think so, maybe I am wrong ).
I think this is an interesting piece of code.
# Include <iostream. h> void bubble2sort (int * pdata, int count) {int itemp; int left = 1; int right = count-1; int T; do {// positive part for (INT I = right; I> = left; I --) {If (pdata [I] <pdata [I-1]) {itemp = pdata [I]; pdata [I] = pdata [I-1]; pdata [I-1] = itemp; t = I ;}} left = t + 1; // reverse part for (I = left; I <right + 1; I ++) {If (pdata [I] <pdata [I-1]) {itemp = pdata [I]; pdata [I] = pdata [I-1]; pdata [I-1] = itemp; t = I ;}} right = T-1 ;} while (left <= right);} void main () {int data [] = {10, 9, 8, 7, 6, 5, 4}; bubble2sort (data, 7 ); for (INT I = 0; I <7; I ++) cout <data [I] <""; cout <"/N ";}