
数据结构
镜水灵动
读万卷书、行万里路、阅人无数、高人指路、贵人相助和自己去悟。
展开
-
有关数组的算法以及二分查找
有关数组的一些算法以及思路原创 2022-12-28 14:50:40 · 230 阅读 · 1 评论 -
通过中序遍历和前序遍历,后续遍历来构建二叉树
通过前序遍历和中序遍历构建二叉树,前提树节点值不重复原创 2022-07-12 19:31:26 · 325 阅读 · 0 评论 -
算法刷题java
一、基础运算1.1 pow 计算x的n次幂private static int simpleN(int i, int n) { int res = 1; int absN = Math.abs (n); while(absN > 0){ res *= i; absN--; } return n > 0 ? res : 1 / res;}public static double powFast(double x, in原创 2021-08-11 19:30:02 · 598 阅读 · 0 评论 -
负载均衡算法总结
1.随机负载均衡思路:(1)用集合list或者set保存全部的资源。(2)产生一个随机数。(3)随机数在0-(list.size()-1) 返回之中(4)返回list.get(随机数)2.轮询负载均衡思路:(1)用集合list或者set保存全部的资源。(2)初始化一个计数器num=0。(3)得到本次的资源list.get((num+1) % (list.size()))(4)更新计数器 num = num+1:3.加权轮询负载均衡为每个资源分配不同的权重例原创 2020-06-26 09:29:14 · 341 阅读 · 0 评论 -
java数据结构---数组,手写数组,算法复杂度分析
1.首先用Java手写一个动态扩容的数组。package com.struct.array;public class Array<E> { /** * 存放数据的数组 */ private E[] data; /** * 数组中现有数据量 */ private int size; public Array(int capacity) { data ...原创 2018-05-27 10:03:43 · 964 阅读 · 2 评论 -
java-二分法查找
1.二分法查找数字在数组中的索引位置2.注意数组特别大,两个数字相加越界问题public class BinarySearch { public static void main(String[] args) { Integer[] dataArr = {1,2,3,4,5,6,7,8,9}; /** * 若区间[start,end],那么传入start,end * ...原创 2018-06-13 08:14:50 · 182 阅读 · 0 评论