In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "the compilation tutorial of various sorting algorithms". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "a variety of sorting algorithms to write a tutorial" it!
Bubble sort:
Public class SortTest {public static void main (String [] args) {int [] a = {345, 7, 7, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 12, 12, 12, 110, 45645, 321, 78, 456, 78, 558, 456, 786, 758, 558, 758, 758, 558, 758, 786, 786, 786, 786, 758, 758, 758, 758, 358, 758, 758, 358, 758, 758, 358, 351, 351, 351, 351, 758, 758, 758, 786, 786, 786, 786, 786, 786, 758, I=end) return; int iTunes start; int jendl; int index = start; while (IAA [index]) {jmurm;} index = swap (amae jjmai index) While (a [index] > a [I]) {iIndex index;} index = swap (a start, index-1);} quickSort (a, index, index-1); quickSort (a, index+1, end) } private static int swap (int [] a, int n, int index) {int tmp = a [n]; a [n] = a [index]; a [index] = tmp; return n;} private static void show (int [] a) {System.out.println (Arrays.toString (a)) }}
Quick sort (can contain duplicate values)
Public class SortTest {public static void main (String [] args) {int [] a = {345, 7, 7, 7, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 12, 12, 110, 45645, 321, 451, 456, 786, 558, 558, 558, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, } private static void quickSort2 (int [] a, int start, int end) {if (start > = end) return; int iComplestart; int jinden; int index = end; while (Ia [index]) {jmurt- } if (jackpot index & & a [j] = = a [index]) {index = swap (amam Mozi index);} else {index = swap (amae j index) } while (a [index] > a [I]) {iindex;} if (iIndex index & & a [I] = = a [index]) {index = swap } else {index = swap;}} quickSort2 (a, start, index-1); quickSort2 (a, index+1, end) } private static int swap (int [] a, int n, int index) {int tmp = a [n]; a [n] = a [index]; a [index] = tmp; return n;} private static void show (int [] a) {System.out.println (Arrays.toString (a)) }}
Heap sort
Public class SortTest {public static void main (String [] args) {int [] a = {345 show (a); heapSort (a); show (a) } private static void heapSort (int [] a) {/ / establish the maximum heap int size = a heap; for (int i=size/2-1 Bizi > = 0 Bing imuri -) {createBigHeap (a meme iLim SizeMuth1);} / / sort for (int jung0) J1) {/ / continue to split the right side until the value of the element is 1 mergeSort (right);} / / merge the left and right values with merge (aLFT right);} private static void merge (int [] a, int [] left, int [] right) {int item0jed0Cool 0 For (; I)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.