java實現各種排序演算法

2021-08-08 13:08:23 字數 1768 閱讀 6685

主要實現了插入,冒泡,選擇,歸併,快速排序

**如下:

package cn.com.cnn;

//從小到大的順序

public

class mysort ;

mysort mysort = new mysort();

int result1 = mysort.choosesort(data);

for(int i : result1)

int result2 = mysort.quicksort(data);

for(int i : result2)

int result3 = mysort.insertsort(data);

for(int i : result3)

int result4 = mysort.mergesort(data);

for(int i : result4)

int result5 = mysort.bubblesort(data);

for(int i : result5)

}//插入排序

public

int insertsort(int data)

data[j + 1] = temp;

}return data;

}//氣泡排序

public

int bubblesort(int data) }}

return data;

}//選擇排序

public

int choosesort(int data)

}int swap = data[i];

data[i] = data[minindex];

data[minindex] = swap;

}return data;

}//快速排序

public

int quicksort(int data)

public

int quicksortcore(int data, int leftindex, int rightindex)

int i = leftindex;

int j =rightindex;

int centernum = data[leftindex];

while(i < j)

data[j] = centernum;

quicksortcore(data, leftindex, j - 1);

quicksortcore(data, j + 1, rightindex);

return data;

}//歸併排序

public

int mergesort(int data)

public

int mergesortcore(int data, int leftindex, int rightindex)

return data;

}public

int merge(int data, int leftindex, int middindex, int rightindex) else

}//將剩餘部分放回中間陣列

while(i <= middindex)

while(j <= rightindex)

int m = 0;

while(leftindex <= rightindex)

return data;

}}

各種排序演算法java實現

插入排序 package org.rut.util.algorithm.support import org.rut.util.algorithm.sortutil author treeroot since 2006 2 2 version 1.0 public class insertsort ...

各種排序演算法java實現

插入排序 package org.rut.util.algorithm.support import org.rut.util.algorithm.sortutil author treeroot since 2006 2 2 version 1.0 public class insertsort ...

各種排序演算法java實現

插入排序 package org.rut.util.algorithm.support import org.rut.util.algorithm.sortutil author treeroot since 2006 2 2 version 1.0 public class insertsort ...