![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法实现
来自流星
这个作者很懒,什么都没留下…
展开
-
二分查找
import java.util.Arrays;public class BinarySearch { public static int rankMethod (int key , int[] a) { int start = 0; int end = a.length - 1; while (start <= end) {...转载 2018-11-14 16:45:41 · 126 阅读 · 0 评论 -
选择排序
package com.arithmetic.sort;import com.Util.StdIn;import com.Util.StdOut;/** * 选择排序 * * 首先找到 数组中最小的元素,将其与数组第一个元素交换位置,再次 在剩下的元素中找到最小与第二个元素 * 数组交换位置。如此反复 选择排序的内循环只是比较当前元素与目前已知元素的最小值,每次交换都能...转载 2018-12-17 10:47:57 · 100 阅读 · 1 评论 -
Stack 链表
package com.arithmetic;import com.Util.StdIn;import com.Util.StdOut;import java.util.Iterator;import java.util.NoSuchElementException;/** * 栈 * 链表实现 */public class Stack<Item> imple...转载 2018-12-14 15:32:32 · 149 阅读 · 0 评论 -
Bag 背包 链表实现
package com.arithmetic;import java.util.Iterator;import java.util.NoSuchElementException;/** * 背包 * 是一种不支持删除元素的集合数据类型。 * 它的目的是帮助我们收集元素和迭代所有元素 */public class Bag<Item> implements Iter...转载 2018-12-13 16:59:50 · 379 阅读 · 0 评论 -
Queue 链表实现
package com.arithmetic;import java.util.Iterator;import java.util.NoSuchElementException;/** * 队列 * 是一种基于先进先出策略的集合类型,按照任务产生的顺序完成他们的策略 * * foreach 语句迭代访问队列元素时的顺序。 就是它们加入队列的顺序 * * 队列链表实现 ...转载 2018-12-13 16:45:39 · 366 阅读 · 0 评论 -
Stack 链表实现
package com.Util;import java.util.Iterator;import java.util.NoSuchElementException;public class Stack<Item> implements Iterable<Item> { private Node<Item> first; // to...转载 2018-12-13 14:49:36 · 191 阅读 · 0 评论 -
Java 单链表
package com.arithmetic;/** * 单链表 */public class SingleLinked { Node first; int N; SingleLinked() { N = 0; } // 头插法 void addHeadNode(Node n) { n.next = ...转载 2018-12-13 14:11:48 · 98 阅读 · 0 评论 -
典型数组处理代码
package com.arithmetic;import java.util.Arrays;public class Array { // 获得数组最大值 public static double getMaxValue(double[] array) { double maxValue = array[0]; for (int i =...转载 2018-11-15 10:39:34 · 123 阅读 · 0 评论 -
典型字符串处理代码
package com.arithmetic;public class StringApi { // 判断字符串是否是一条回文 public static boolean isPalindrome(String s) { int N = s.length(); for (int i = 0; i < N/2; i++) { ...转载 2018-11-19 10:57:04 · 213 阅读 · 0 评论 -
格式化输出
package com.arithmetic;// 格式化输出public class Format { public static void main(String[] args) { // 字符 String s = "hello world"; System.out.printf("%-16s",s); Syst...转载 2018-11-16 15:14:46 · 106 阅读 · 0 评论 -
相关API
package com.arithmetic;import java.util.Arrays;public class StdRandom { // 随机返回【a,b)之间的一个 double 值 public static double uniform(double a, double b) { return a + random() * (b-a);...转载 2018-11-16 14:36:16 · 166 阅读 · 0 评论 -
插入排序
package com.arithmetic.sort;import com.Util.StdOut;/** * 整理牌的方法是一张一张的来,将每一张插入到其他已经有序的牌的适当位置中。 * * 在实现中我们需要给插入的元素腾出空间,我们需要将其余所有元素在插入之前都向右移动一位. * * 与选择排序一样。 当前索引左边的都是有序的,但它们的最终位置还不确定,为了给更小的元素腾...转载 2018-12-18 09:01:21 · 123 阅读 · 0 评论