一致性hash算法:https://www.cnblogs.com/xrq730/p/5186728.html
需要知道什么是hash一致性算法,并且其中的一些概念?
http://www.zsythink.net/archives/1182
java 排序算法实现:
冒泡排序:
/*
遍历一遍,把最大的放到最后
例子:2,1,7,4,3
比较第一次:1,2,7,4,3
比较第二次:1,2,7,4,3
比较第三次:1,2,4,7,3
比较第四次:1,2,4,3,7
*/
public int[] bubbleSort(int[] nums) {
int length = nums.length;
int curr = 0;
for(int i = 0; i < length; i++) {
for(int j = 0; j< length -i-1;j++) {
if (nums[j] > nums[j+1]) {
curr = nums[j];
nums[j] = nums[j+1];
nums[j+1] = curr;
}
}
}
return nums;
}
时间复杂度:O(n*n)
鸡尾酒排序,冒泡排序的改进,正反向遍历
/**
*鸡尾酒排序
* @param nums
* @return
*/
public int[] bubbleSort2(int[] nums) {
int length = nums.length;
int num = 0;
for (int i = 0;i < length/2 ; i++) {
/*正向循环*/
for (int j = i; j < length-i-1;j++) {
if (nums[j] > nums[j+1]) {
num = nums[j];
nums[j] = nums[j+1];
nums[j+1] = num;
}
}
for (int j= length-i-1; j > i;j--) {
if (nums[j] < nums[j-1]) {
num = nums[j];
nums[j-1] = nums[j];
nums[j] = num;
}
}
}
return nums;
}
时间复杂度也是O(n*n)
选择排序,选择最大的,交换位置
public int[] choiceSort(int[] nums){
int localtion = 0;
int curr = 0;
int length = nums.length;
for (int i = 0; i < length; i++) {
for (int j = i; j < length;j++) {
if (nums[j] > nums[localtion]) {
localtion = j;
}
}
curr = nums[i];
nums[i] =nums[localtion];
nums[localtion] = curr;
localtion = i+1;
}
return nums;
}
时间复杂度也是O(n*n)
https://github.com/francistao/LearningNotes/blob/master/Part3/Algorithm/Sort/%E9%9D%A2%E8%AF%95%E4%B8%AD%E7%9A%84%2010%20%E5%A4%A7%E6%8E%92%E5%BA%8F%E7%AE%97%E6%B3%95%E6%80%BB%E7%BB%93.md
http://www.hollischuang.com/archives/2509
jvm
https://juejin.im/post/5b42c01ee51d45194e0b819a?utm_source=gold_browser_extension
网友评论