package test;

import java.util.Scanner;

public class JavaSort {

	public static void quickSort(int a[], int left, int right) {
if (a == null || a.length == 0)
return;
if (left >= right)
return; int i = left;
int j = right; int key = a[left]; while (i < j) {
while (i < j && key <= a[j]) {
j--;
}
a[i] = a[j]; while (i < j && key >= a[i]) {
i++;
}
a[j] = a[i];
} a[i] = key;
quickSort(a, left, i - 1);
quickSort(a, i + 1, right);
} public static void InsertSort(int[] a) {
if (a == null || a.length == 0)
return;
int i, j, key; for (i = 1; i < a.length; i++) {
key = a[i];
j = i - 1;
while (j >= 0 && a[j] > key) {
a[j + 1] = a[j];
j--;
}
a[j + 1] = key;
}
} public static void BubbleSort(int[] a) {
if (a == null || a.length == 0)
return;
int i, j;
for (i = 0; i < a.length; i++) {
for (j = a.length - 2; j >= i; j--) {
if (a[j] > a[j + 1]) {
a[j] = a[j + 1] ^ a[j];
a[j + 1] = a[j + 1] ^ a[j];
a[j] = a[j + 1] ^ a[j];
}
}
}
} public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String line = sc.nextLine();
String[] strs = line.split(",");
int nums[] = new int[strs.length];
int i = 0; for (String s : strs) {
nums[i++] = Integer.parseInt(s);
} System.out.println("quick sort");
quickSort(nums, 0, nums.length - 1); for (int j : nums) {
System.out.println(j);
} System.out.println("insert sort");
InsertSort(nums);
for (int j : nums) {
System.out.println(j);
} System.out.println("bubble sort");
BubbleSort(nums);
for (int j : nums) {
System.out.println(j);
} sc.close();
} }

最新文章

  1. 高访问量WEB开发中的架构模式,学习从点滴开始
  2. java 执行 jar 包中的 main 方法
  3. Ubuntu14.04使用apt-fast来加快apt-get下载的教程
  4. symfony2取得web目录绝对路径、相对路径、网址的函数是什么
  5. django rest_framework--入门教程
  6. spring中的DisposableBean和InitializingBean,ApplicationContextAware的用法
  7. ason 和 Java 对象转化示例
  8. zepto判断手机横竖屏
  9. C#中的文件同步
  10. HDU 1404 (博弈) Digital Deletions
  11. duilib底层机制剖析:窗体类与窗体句柄的关联
  12. java返回参数中几种常见的方法
  13. 【百度地图API】建立全国银行位置查询系统(四)——如何利用百度地图的数据生成自己的标注
  14. stm32-ucos移植lwip-1(raw)
  15. 从零开始学习C#——HelloWorld(一)
  16. 去掉标题栏的方法(使用requestWindowFeature(Window.FEATURE_NO_TITLE);为什么失效)
  17. vue系列之动态路由【原创】
  18. linux - 目录、文件默认属性: umask使用
  19. ES集群
  20. SignalR NuGet程序包

热门文章

  1. extjs学习资料
  2. 帆软报表FineReport中数据连接之Jboss配置JNDI连接
  3. 【转载】Serif和Sans-serif字体的区别
  4. python高级之操作数据库
  5. ES5/标准 ECMAScript 内置对象
  6. android第一行代码-5.监听器的两种用法和context
  7. 通过bitmap对100w数字进行排序去重
  8. MBR与GPT
  9. tagfield
  10. BZOJ 2286 消耗战 (虚树+树形DP)