易截截图软件、单文件、免安装、纯绿色、仅160KB

java:三种经典大排序汇总,冒泡,插入,选择

package arrays.myArray;
public class SortArr {
 public static void main(String[] args) {
  int[] arrInt = { 4, 7, 8, 5, 6, 3, 2, 3, 4 };
  maoPaoSort(arrInt);
  print("冒泡排序:", arrInt);
  arrInt = new int[]{ 4, 7, 8, 5, 6, 3, 2, 3, 4 };
  insertSort(arrInt);
  print("插入排序:", arrInt);
  arrInt = new int[]{ 4, 7, 8, 5, 6, 3, 2, 3, 4 };
  checkSort(arrInt);
  print("选择排序:", arrInt);
 }
 // 冒泡排序
 private static void maoPaoSort(int[] arrInt) {
  int temp = 0;
  for (int i = 0; i < arrInt.length; i++) {
   for (int j = 0; j < arrInt.length - 1; j++) {
    if (arrInt[i] < arrInt[j]) {
     temp = arrInt[i];
     arrInt[i] = arrInt[j];
     arrInt[j] = temp;
    }
   }
  }
 }
 // 插入排序
 private static void insertSort(int[] arrInt) {
  //倒数第二个开始比较
  for (int i = arrInt.length - 2; i >= 0; i--) {
   int j = 0;
   for (j = arrInt.length - 1; j > i; j--) {
    if (arrInt[i] > arrInt[j]) {
     break;
    }
   }
   int temp = arrInt[i];
   for (int k = i; k < j; k++) {
    arrInt[k] = arrInt[k + 1];
   }
   arrInt[j] = temp;
  }
  
  //正数第二个开始比较
  /*for (int i = 1; i < arrInt.length; i++) {
   int j = 0;
   for (j = 0; j < arrInt.length - 1; j++) {
    if (arrInt[i] > arrInt[j]) {
     break;
    }
   }
 &nbs


相关文档:

java 根据两点经纬度来算距离

package com.njty.util;
public class Test {
  private static final double EARTH_RADIUS = 6378137;
  private static double rad(double d)
     {
        return d * Math.PI / 180.0;
     }
     ......

java:大数据文件写入,读取,分割,排序,合并

package arrays.file;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
i ......

java:经典文件写入和读取,速度超快

package arrays.file;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamRea ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号