快速排序

public class quickSort { public static void main(String[] args) { int[] nums = {5, 2, 6, 3, 8}; quick_sort02(nums, 0, nums.length - 1); for (int i : nums) { System.out.print(i + " "); } }

text
复制代码
public static void quick_sort02(int[] p, int L, int R) { if (L >= R) return; int i = L - 1; int j = R + 1; int x = p[L + R >> 1]; while (i < j) { do i++; while (p[i] < x); do j--; while (p[j] > x); if (i < j) { //int t; //t = p[j]; //p[j] = p[i]; //p[i] = t; //位运算交换数字 p[j] ^= p[i]; p[i] = p[j] ^ p[i]; p[j] = p[j] ^ p[i]; } } quick_sort02(p, L, j); quick_sort02(p, j + 1, R); }

}

0个评论
点击登录,快来和大家讨论吧~
表情
图片
暂无评论
下载 APP