随笔分类 - 算法相关
摘要:代码 public class MergeSort { public static void main(String[] args) { // int[] arr = {8,4,5,7,1,3,2,6}; // int[] temp = new int[arr.length]; // System.
阅读全文
摘要:代码 public static void quickSort(int[] arr,int left,int right){ int l = left; int r = right; //pivot 中轴值 int pivot = arr[(left + right) / 2]; int temp
阅读全文
摘要:交换式 代码 protected static void shellSort1(int[] arr) { int temp = 0; for(int gap = arr.length / 2;gap > 0; gap /= 2){ for(int i = gap;i < arr.length; i
阅读全文
摘要:代码 public class InsertSort { static int[] arr = {6,7,0,-5,8,1,3,2}; public static void main(String[] args) { System.out.println("排序前:" +Arrays.toStrin
阅读全文
摘要:代码(带优化) public class SelectSort { static int[] arr = {6,7,0,-5,8,1,3,2}; public static void main(String[] args) { System.out.println("排序前:" + Arrays.t
阅读全文
摘要:代码 package com.suanfa; import java.util.Arrays; /** * TODO * * @author kakaluote * @date 2021年9月10日 上午9:07:58 */ public class BubbleSort { static int[
阅读全文
摘要:代码 public class Queue8 { //有几个皇后 int max = 8; //皇后存放位置的结果 int[] array = new int[max]; static int count = 0; static int judgeCount = 0; public static v
阅读全文
摘要:/** * TODO 约瑟夫问题(丢手绢问题) * * @author kakaluote * @date 2021年8月30日 下午3:57:05 */ public class Josepfu { public static void main(String[] args) { CircleSi
阅读全文
摘要:public class DoubleLinkedListDemo { public static void main(String[] args) { HeroNode2 heroNode5 = new HeroNode2(5, "卡卡5", "赛亚人"); HeroNode2 heroNode1
阅读全文
摘要:实现代码 /** * TODO * * @author kakaluote * @date 2021年8月17日 下午4:36:49 */ public class SingleLinkedListDemo { public static void main(String[] args) { Her
阅读全文
摘要:public class CircleArrayQueueDemo { public static void main(String[] args) { System.out.println("测试模拟环形队列的案例~"); //有效个数3个,因为有一个空位 CircleArrayQueue que
阅读全文
摘要:代码 public class ArrayQueueDemo { public static void main(String[] args) { ArrayQueue queue = new ArrayQueue(3); char key = ' '; Scanner scanner = new
阅读全文
摘要:分析过程 将两个有序的单链表合并成一个有序的单链表,本人的思路是利用第三个单链表存储两个单链表的节点,若两个链表均为空,则直接返回;若其中一个链表为空,则直接将另一个链表连接至链表3上;若两个链表均不为空,先将其中一个链表1连接至链表3,然后遍历另一个链表2,将链表2中的节点按照顺序连接至链表3上。
阅读全文
摘要:参考力扣第一题 public class TestSum { int[] arrs = {19,15,88,65,105,858,645,145,868,2,35,78,66,7,159}; int target = 9; public static void main(String[] args)
阅读全文
摘要:算法是什么 算法(Algorithm)是指用来操作数据、解决程序问题的一组方法。对于同一个问题,使用不同的算法,也许最终得到的结果是一样的,但在过程中消耗的资源和时间却会有很大的区别。 时间维度:是指执行当前算法所消耗的时间,我们通常用「时间复杂度」来描述。 空间维度:是指执行当前算法需要占用多少内
阅读全文

浙公网安备 33010602011771号