数组的原地排序和保护排序
来源:互联网 发布:卡司数据 编辑:程序博客网 时间:2024/06/06 15:43
import java.util.Arrays;public class SortArray { public static void main(String[] args) { //对数组进行原地排序 int[] a = { 2, 4, 6, 8, 1, 3, 5, 7 }; sort_1(a); print(a); //对数组进行原地排序 int[] x = { 2, 4, 6, 8, 1, 3, 5, 7 }; int[]y = sort_2(x); print(x); print(y); } private static int[] sort_2(int[] a) { int[]b = new int[a.length]; //复制数组a到数组b System.arraycopy(a, 0, b, 0, a.length); //对数组b进行排序 Arrays.sort(b); return b; } private static void sort_1(int[] a) { Arrays.sort(a); } private static void print(int[] b) { for (int i : b) { System.out.print(i+" "); } System.out.println(); }}
打印出来的是:
1 2 3 4 5 6 7 8
2 4 6 8 1 3 5 7
1 2 3 4 5 6 7 8
阅读全文
0 0
- 数组的原地排序和保护排序
- 可以进行原地排序的计数排序
- 单链表的原地归并排序实现
- 原地排序-更简洁的算法
- 原地归并排序
- 原地归并排序
- 原地置换排序
- 原地归并排序变形
- 原地归并排序
- 原地归并排序
- 原地归并排序
- 原地归并排序
- 原地归并排序
- C原地快速排序
- 原地归并排序
- 原地归并排序
- 原地归并排序
- 原地归并排序
- 理解Java内部类 匿名内部类
- stuff.split("xxxx")
- leetcode 35. Search Insert Position(C语言,查询插入位置)19
- eclipse中Tomcat启动时报错Cannot assign requested address
- Java图片处理开源框架
- 数组的原地排序和保护排序
- 适配器设计模式
- 栈和队列---最大值减去最小值小于或等于num的子数组数量
- PAT 甲级 1055. The World's Richest (25)
- 敏捷转型中常见的问题
- 趣味回顾会-回顾
- 趣味回顾会-鼓舞团队热情
- 如何进行高效迅速的CodeReview
- 趣味回顾会之Check in