mb61ab40ce80d9c 2022-01-15 03:09:42 阅读数:831
@author JourWon
*/
public static void heapSort(int[] array) {
if (array == null || array.length <= 1) {
return;
}
int length = array.length;
//1. Build the big top heap
for (int i = length / 2 - 1; i >= 0; i--) {
// From the first non leaf node, from bottom to top , Adjust the structure from right to left
adjustHeap(array, i, length);
}
//2. Adjust heap structure + Swapping top and end elements
for (int j = length - 1; j > 0; j--) {
// Exchange the top element with the end element
swap(array, 0, j);
// Readjust the heap
adjustHeap(array, 0, j);
}
}
/**
Description: Adjustment of the GTR ( It's just the adjustment process , Based on the built-up of the GTR )
@param array
@param i
@param length
@return void
@author JourWon
*/
private static void adjustHeap(int[] array, int i, int length) {
《 A big factory Java Analysis of interview questions + Back end development learning notes + The latest architecture explanation video + Practical project source code handout 》
【docs.qq.com/doc/DSmxTbFJ1cmN1R2dB】 Full content open source sharing
// Take out the current element first i
int temp = array[i];
// from i The left child of the node begins , That is to say 2i+1 Start at
for (int k = i 2 + 1; k < length; k = k 2 + 1) {
// If the left child node is less than the right child node ,k Point to the right child node
if (k + 1 < length && array[k] < array[k + 1]) {
k++;
}
// If the child node is larger than the parent node , Assign the child node value to the parent node ( There's no exchange )
if (array[k] > temp) {
array[i] = array[k];
i = k;
} else {
break;
}
}
// take temp Put the value in the final position
array[i] = temp;
}
/**
Description: Exchange element positions
@param array
@param a
@param b
@return void
@author JourWon
*/
private static void swap(int[] array, int a, int b) {
int temp = array[a];
array[a] = array[b];
array[b] = temp;
}
Many people have been interviewing recently , I have also collated a lot of interview materials , There are also other big factories . I hope I can help you .
The latest interview questions
The answers to the above interview questions are all organized into document notes . I also sorted out some interview materials & newest 2021 I collected some real interview questions from big factories
Latest finishing e-book
The latest collation of large factory interview documents
The above is the whole content of this paper , I hope it will be helpful for your study , I also hope that you can support .
This article has been CODING Open source project :【 A big factory Java Analysis of interview questions + Core summary learning notes + The latest explanation video + Actual project source code 】 Included
版权声明:本文为[mb61ab40ce80d9c]所创,转载请带上原文链接,感谢。 https://javamana.com/2021/12/202112122254390100.html