public static void insertsort(int arr)
arr[j + 1] = tmp;
}public static void bubblesort(int arr)
}system.out.println("第"+(arr.length-length)+"趟:"+arrays.tostring(arr));
length--;
if(flag == false)
}}(1):將序列分成有序區和無序區,初始時有序區為空,無序區包括全部元素
(2):每次從無序區中選擇最小的元素將其與無序區第乙個元素進行交換
(3):重複(2),直到無序區沒有元素public static void selectsort(int arr)
}//最小元素不是本身
if(index != i)
}}##歸併排序
public static void mergesort(int list)
}public static int merge(int list1,int list2)else if(list1[pos1] > list2[pos2])else
}while(pos1 < list1.length)
while(pos2 < list2.length)
return temp;
}public static void quicksort(int arr,int low,int high)
}//找尋分界點
public static int partition(int arr,int low , int high)
//從右邊找比pivot小或等於的數
while(high >= low && arr[high] > pivot )
//交換
if(high > low)
}//此時high = low - 1;
//且high之前的元素都小於等於pivot,low之後的元素都大於pivot
"low="+low+";high="+high+":"+arrays.tostring(arr));
if(high > first)else
}堆是一棵具有以下屬性的二叉樹
1、一棵完全二叉樹
2、每個節點大於(小於)或等於它的任意乙個孩子
分類:大頂堆,小頂堆public static void heapsort(int arr)}}
public static void initheap(int arr)else}}
}public static void adjustheap(int arr,int end)
int temp = arr[current];
arr[current] = arr[index];
arr[index] = temp;
current = index;
}else
}else if(left <= end && right > end)else
}else}}
各種排序演算法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 ...