- 博客(35)
- 收藏
- 关注
原创 仅用位运算实现加减乘除
import java.util.Arrays; public class 位运算 { public static void main(String[] args) { // TODO Auto-generated method stub System.out.println(add(12, 15)); System.out.println(subs(12, 15)); System.out.println(mult(14, 5)); System.out.println(Arra
2020-09-28 00:13:31
173
原创 predicate/Stream操作集合
/** * 操作集合 */ import java.util.Collection; import java.util.HashMap; import java.util.function.Predicate; import java.util.function.ToIntFunction; public class Test_Collection { public static void main(String[] args) { HashMap<Integer, S
2020-09-21 20:28:43
299
原创 RadixSort
import java.util.ArrayList; import java.util.List; import java.util.Arrays; import java.util.Random; public class RadixSort { /* * Radix sort an array of Strings * Assume all are all ASCII * Assume all have same length */ publ.
2020-09-07 16:19:58
205
原创 QuickSort/QuickSelect-双指针nb
/** * 填坑法实现简易版本,实现好像和下面的一样?? */ import java.util.Arrays; import java.util.Random; public class BinarySort { public static void main(String[] args) { int[] arr = new int[20]; for (int i = 0; i < arr.length; i++) { arr.
2020-09-07 11:39:13
236
原创 mergeSort
/** * 填坑法实现,不需要借助额外数组 */ import java.util.Arrays; import java.util.Random; public class BinarySort { public static void main(String[] args) { int[] arr = new int[80]; for (int i = 0; i < arr.length; i++) { arr[i] = n.
2020-09-06 21:47:30
164
原创 shellsort and heapsort
public static void main(String[] args) { int[] ar = {1, 4, 3, 5, 7, 11, 9, 10, 0, 1, 6, 3, 5, 4, 8}; heapsort(ar); System.out.println(Arrays.toString(ar)); } public static void shellsort(int[] a) { for (int gap ...
2020-09-05 18:13:28
167
原创 BinomialQueue
package heap;// BinomialQueue class // // CONSTRUCTION: with no parameters or a single item // // ******************PUBLIC OPERATIONS********************* // void insert( x ) --> Insert x // Comparable deleteMin( )--> Return and remove smallest
2020-09-05 18:10:33
325
原创 LeftistHeap
package heap;// LeftistHeap class // // CONSTRUCTION: with a negative infinity sentinel // // ******************PUBLIC OPERATIONS********************* // void insert( x ) --> Insert x // Comparable deleteMin( )--> Return and remove smallest ite
2020-09-05 18:09:44
189
原创 UnderfolwException
package heap; /** * Exception class for access in empty containers * such as stacks, queues, and priority queues. * @author Mark Allen Weiss */ public class UnderflowException extends RuntimeException { }
2020-09-05 18:09:14
170
原创 BinaryHeap
package heap;// BinaryHeap class // // CONSTRUCTION: with optional capacity (that defaults to 100) // or an array containing initial items // // ******************PUBLIC OPERATIONS********************* // void insert( x ) --> Insert
2020-09-05 18:08:13
199
原创 HashFamily
package hash; interface HashFamily<AnyType> { int hash( AnyType x, int which ); int getNumberOfFunctions( ); void generateNewFunctions( ); } import hash.HashFamily; import java.util.Random; public class StringHashFamily implements Has
2020-09-05 18:05:29
256
原创 CuckooHashTableClassic
package hash; import java.util.HashSet; // Cuckoo Hash table class // // CONSTRUCTION: a hashing function family and // an approximate initial size or default of 101 // // PUBLIC OPERATIONS*** // bool insert( x ) --> Insert x // bool
2020-09-05 18:02:21
147
原创 CuckooHashTable
package hash; import java.util.Random; // Cuckoo Hash table class // // CONSTRUCTION: a hashing function family and // an approximate initial size or default of 101 // // PUBLIC OPERATIONS*** // bool insert( x ) --> Insert x // bool
2020-09-05 18:01:13
410
原创 MyArrayList
package list; public class MyArrayList<AnyType> implements Iterable<AnyType> { /** * Construct an empty ArrayList. */ public MyArrayList( ) { doClear( ); } /** * Returns the number of items in th
2020-09-02 19:32:10
185
原创 MyLinkedList
package list; /** * LinkedList class implements a doubly-linked list. */ public class MyLinkedList<AnyType> implements Iterable<AnyType> { /** * Construct an empty LinkedList. */ public MyLinkedList() { doClear();
2020-09-02 19:31:03
409
转载 SeparateChainingHashTable
package hash; import java.util.LinkedList; import java.util.List; // SeparateChaining Hash table class // // CONSTRUCTION: an approximate initial size or default of 101 // // ******************PUBLIC OPERATIONS********************* // void insert( x )
2020-09-02 19:29:39
432
原创 QuadraticProbingHashTable
package hash; // QuadraticProbing Hash table class // // CONSTRUCTION: an approximate initial size or default of 101 // // ******************PUBLIC OPERATIONS********************* // bool insert( x ) --> Insert x // bool remove( x ) --> R
2020-09-02 19:29:29
361
原创 SplayTree
package tree;// SplayTree class // // CONSTRUCTION: with no initializer // // ******************PUBLIC OPERATIONS********************* // void insert( x ) --> Insert x // void remove( x ) --> Remove x // boolean contains( x ) --> Retu
2020-09-02 19:28:36
121
原创 BinarySearchTree
package tree;// BinarySearchTree class // // CONSTRUCTION: with no initializer // // ******************PUBLIC OPERATIONS********************* // void insert( x ) --> Insert x // void remove( x ) --> Remove x // boolean contains( x ) --&g
2020-09-02 19:27:59
129
原创 AVLTree
package tree;// AvlTree class // // CONSTRUCTION: with no initializer // // ******************PUBLIC OPERATIONS********************* // void insert( x ) --> Insert x // void remove( x ) --> Remove x (unimplemented) // boolean contains( x
2020-09-02 19:27:13
105
原创 一行搞定平年闰年
Scanner scan = new Scanner(System.in); System.out.println("请输入年份"); int n = scan.nextInt(); System.out.println(n + ((n % 100 == 0 ? n /= 100 : n) % 4 == 0 ? "年是闰年" : "年是平年"));
2020-09-02 16:39:05
122
原创 while实现乘方,乘法,二进制数中的1个数
public static void main(String[] args) { System.out.println(sub(3, 12)); System.out.println(pow(3, 4)); int a = 127; System.out.println(Integer.toBinaryString(a)); System.out.println(num(a)); } /** * .
2020-08-27 17:10:00
276
原创 数据结构与算法分析2-28
使用正数的数组a设计有效的算法以确定: 没考虑i==j import java.util.Arrays; import java.util.Random; public class 计算数组中两数之和最大值 { public static void main(String[] args) { int[] arr = new int[10]; for (int i = 0; i < arr.length; i++) { arr[i]
2020-08-24 20:30:52
169
转载 eclipse常用快捷键
Eclipse 常用快捷键 快捷键 描述 编辑 Ctrl+1 快速修复(最经典的快捷键,就不用多说了,可以解决很多问题,比如import类、try catch包围等) Ctrl+Shift+F 格式化当前代码 Ctrl+Shift+M 添加类的import导入 Ctrl+Shift+O 组织类的import导入(既有Ctrl+Shift+M的作用,又可以帮你去除没用的导入,很有用) Ctrl+Y 重做(与撤销Ctrl+Z相反) Alt+/
2020-08-20 09:28:55
125
转载 拆分和合并一个文件java练习
package stream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; public class Splite { public static void main(String[] args) throws IOException { String fil = "D:/testFolder/So
2020-08-19 19:06:19
115
原创 遍历文件夹练习
遍历某个目录下所有的文件(包括子目录),找出这些文件里,最大的和最小(非0)的那个文件,打印出他们的文件名 package file; import java.io.File; import java.util.ArrayList; public class Files { public static void main(String[] args) { File file = new File("D:/testFolder"); list(file);
2020-08-19 16:38:32
174
原创 日期系列java练习
package date; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Homework { @SuppressWarnings("deprecation") public static void main(String[] args) throws ParseExcep
2020-08-19 10:56:42
184
原创 JAVA常见字符串方法
package digit; public class TestString { public static void main(String[] args) { /* * 9给出一句英文句子: "let there be light" 得到一个新的字符串,每个单词的首字母都转换为大写 */ String sentence1 = "let there be light"; String[] word1 = sen
2020-08-19 00:50:53
115
原创 控制台读取字符
通过Scanner从控制台读取字符串,然后把字符串转换为字符数组 参考的转换方式: String str = “abc123”; char[] cs = str.toCharArray(); 转换为字符数组后,筛选出控制台读取到的字符串中的大写字母和数字,并打印出来 // 提取输入在控制台上的字符串中的大写字母和字符串 public static void uperandNum() { Scanner scan = new Scanner(System.in);
2020-08-18 17:55:53
436
原创 字符串数组排序java练习
创建一个长度是8的字符串数组 使用8个长度是5的随机字符串初始化这个数组 对这个数组进行排序,按照每个字符串的首字母排序(无视大小写) 注1: 不能使用Arrays.sort() 要自己写 注2: 无视大小写,即 Axxxx 和 axxxxx 没有先后顺序 package character; import java.util.Arrays; import java.util.Random; import java.util.Scanner; public class TestChar { p
2020-08-18 17:40:48
533
翻译 数组排序,二分法
public class Sort { public static void main(String[] args) { int[] arr = {35,24,33,54,27,91,2,34,78,84,32,66,13,21}; sort3(arr,0,arr.length-1); for(int i=0;i<arr.length;i++){ System.out.println("arr["+i+"]:"+arr[i
2020-08-07 16:49:54
537
原创 java实现:啤酒2元一瓶,10个盖子可以换一瓶啤酒,4个瓶子可以换一瓶啤酒,请问x元最多可换多少瓶啤酒
花钱买酒 public class Maijiu { public static void main(String[] args) { // TODO Auto-generated method stub //啤酒2元一瓶,10个盖子可以换一瓶啤酒,4个瓶子可以换一瓶啤酒,请问x元最多可换多少瓶啤酒 System.out.println(new Maijiu().sum(26, 2, 2)); } //现金、空盖子数、空瓶子数
2020-08-07 13:53:37
543
原创 查询数组,普通、二分法、递归
数组查询,学习使用二分法 代码片. //使用了递归 //通过数组arr,初始0,arr.length,需要查询的数字,作为签名参数 public static int search(int[] arr,int low,int high,int key){ while(low<=high){ int mid = (low+high)/2; if(arr[mid]==key){ return mid;
2020-08-07 12:30:32
119
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅