美文网首页
数组中交换两个数字

数组中交换两个数字

作者: 卡路fly | 来源:发表于2020-05-19 15:36 被阅读0次
    public static void swap(int[] numbers, int i, int j) {
            int temp = numbers[i];
            numbers[i] = numbers[j];
            numbers[j] = temp;
        }
    
        public static void swap1(int[] numbers, int i, int j) {
            numbers[i] = numbers[i] + numbers[j];
            numbers[j] = numbers[i] - numbers[j];
            numbers[i] = numbers[i] - numbers[j];
        }
    
        public static void swap2(int[] numbers, int i, int j) {
            numbers[i] = numbers[i] ^ numbers[j];
            numbers[j] = numbers[i] ^ numbers[j];
            numbers[i] = numbers[i] ^ numbers[j];
        }
    

    相关文章

      网友评论

          本文标题:数组中交换两个数字

          本文链接:https://www.haomeiwen.com/subject/hgnuohtx.html