随笔分类 -  常用算法

摘要:1、输入三个数a、b、c,按大小顺序输出 可以利用冒泡排序去实现,代码如下所示: /** * 输入三个数a\b\c,按大小顺序输出 * * @param arrays arrays */ private static void arraySort(int[] arrays) { for (int i 阅读全文
posted @ 2021-06-14 14:58 jason小蜗牛 阅读(843) 评论(0) 推荐(0) 编辑
摘要:java代码实现 public class SubArray { public static int sub(int[] A, int[] B) { int flag = -1; for (int i = 0; i < A.length - B.length + 1; i++) {//7 for ( 阅读全文
posted @ 2020-07-11 18:15 jason小蜗牛 阅读(398) 评论(0) 推荐(0) 编辑
摘要:递归算法就是在调用自己,循环的调用。是一种解决问题的常用算法,比较简单易于分析。递归有两个基本要素:边界条件,即确定递归何时停止运行,也叫递归出口;另一个就是递归模式,也就是如何将大问题分解为小问题的,也叫递归体。 int getR(int num){ if(num==1) return num; 阅读全文
posted @ 2019-09-22 20:01 jason小蜗牛 阅读(2534) 评论(0) 推荐(0) 编辑
摘要:二叉树基础知识 1. 树定义 树(Tree) 是n(n =0)个结点的有限集。n=0时称为空树。在任意一颗非空树中: 1)有且仅有一个特定的称为根(Root)的结点; 2)当n 1时,其余结点可分为m(m 0)个互不相交的有限集T1、T2、......、Tn,其中每一个集合本身又是一棵树,并且称为根 阅读全文
posted @ 2019-08-22 17:40 jason小蜗牛 阅读(1089) 评论(0) 推荐(0) 编辑
摘要://二分查找的前提是有序的数。public class BinarySearch { public static void main(String[] args) { int[] arr = {1, 2, 4, 5, 6, 8, 9, 10}; System.out.println(binarySe 阅读全文
posted @ 2019-04-28 15:33 jason小蜗牛 阅读(178) 评论(0) 推荐(0) 编辑
摘要://选择排序//基本思想:从原始数组中寻找最小的那个数,然后与第一个数交换,依次类推public class SelectionSort { public static void main(String[] args) { int[] arr = {1, 4, 15, 63, 33, -1, 0, 阅读全文
posted @ 2019-04-28 14:56 jason小蜗牛 阅读(218) 评论(0) 推荐(0) 编辑
摘要://插入排序//从第一个元素开始,每个数往前插入,后一个数与前一个数相比较,如果后一个数小于前一个数,则将后一个数往前移位。public class InsertSort { public static void main(String[] args) { int[] arr = {-2, 52, 阅读全文
posted @ 2019-04-28 14:50 jason小蜗牛 阅读(199) 评论(0) 推荐(0) 编辑
摘要://两数交换不用中间变量public class TwoChange { public static void main(String[] args) { int a = 3, b = 5; //第一种方式采用加减法实现 /* a = a + b; b = a - b; a = a - b;*/ / 阅读全文
posted @ 2019-04-27 16:32 jason小蜗牛 阅读(322) 评论(0) 推荐(0) 编辑
摘要:快速排序是冒泡排序的改进,效率比较高,基本思想也是两两相比较。 阅读全文
posted @ 2019-04-27 16:24 jason小蜗牛 阅读(199) 评论(0) 推荐(0) 编辑
摘要://冒泡排序//冒泡排序要经过N-1步的中间排序才能排完,效率较低public class BublleSort { public static void main(String[] args) { int[] arr = {1, 56, 36, 74, 2, 6, 3, 21, 5}; bubbl 阅读全文
posted @ 2019-04-27 14:57 jason小蜗牛 阅读(183) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示