欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

探讨基于启发式方法的Bubble Sort算法详解

最编程 2024-07-30 06:59:32
...
public int[] sorth(int[] data) { /* your code goes here */ boolean swapped; int i, n = data.length; do { swapped = false; ctrs.count(passCounter); for (i = 0; i <= n - 2; i++) { if (data[i] > data[i + 1]) { swap(data, i, i + 1); swapped = true; } ctrs.count(cmpCounter); } if (!swapped) { break; } swapped = false; ctrs.count(passCounter); for (i = n - 2; i >= 0; i--) { if (data[i] > data[i + 1]) { swap(data, i, i + 1); swapped = true; } ctrs.count(cmpCounter); } } while (swapped); return data; }