![](https://img-blog.csdnimg.cn/20201014180756738.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法
文章平均质量分 73
我橘子超酸
这个作者很懒,什么都没留下…
展开
-
计算数组中任意两数的差的绝对值的最小值
given an array with N integer elements, please find out the minimum absolute value of the difference betweent any two elements from the array.原创 2022-09-03 17:44:18 · 1198 阅读 · 0 评论 -
队列与栈,BFS与DFS
1.广度优先搜索与队列1.1使用广度优先搜索的两种情景:1.遍历图或树2.寻找最短路径1.2模板1.2.1寻找最短路径为什么是最短?从根节点出发,按层遍历,当目标第一个被访问一定是层数最少的访问模板一对于一个节点肯能访问多次适用于1.没有循环的情况(树的遍历)2.确实希望多次将节点添加到队列中/** * Return the length of the shortest path between root and target node. */int BFS(Node roo原创 2020-10-28 17:01:14 · 472 阅读 · 0 评论 -
java实现计算器,能够进行负数运算
import java.util.*;import java.util.Stack;public class Three { public static void main(String[] args){ Double result = Calculate.result("(3+1)+1/3+9"); System.out.println(result); }}class Calculate { //计算结果 public stati原创 2020-10-11 20:36:55 · 2184 阅读 · 0 评论 -
克鲁斯卡尔求最小生成树——并查集的应用
参考:https://www.cnblogs.com/yoke/p/6697013.html克鲁斯卡尔算法克鲁斯卡尔算法的基本思想是以边为主导地位,始终选择当前可用(所选的边不能构成回路)的最小权植边。所以Kruskal算法的第一步是给所有的边按照从小到大的顺序排序。这一步可以直接使用库函数qsort或者sort。接下来从小到大依次考察每一条边(u,v)。具体实现过程如下:<1> 设一个有n个顶点的连通网络为G(V,E),最初先构造一个只有n个顶点,没有边的非连通图T={V,空},图中每原创 2020-05-21 18:25:52 · 295 阅读 · 0 评论