This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
public class MergeSort { | |
/** | |
* 将一个数组中的两个有序序列合并成一个新的有序序列 | |
* @param list 要排序的数组 | |
* @param left 数组的左边界 | |
* @param middle 数组的中间元素的下标 | |
* @param right 数组的右边界 | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class Recursion { | |
/** | |
* 计算 n 的阶乘 | |
* @param n 非负整数 | |
* @return n 的阶乘 | |
*/ | |
private static int factorial(int n) { | |
if (n == 0) { // 如果 n 是 0,说明算到阶乘的最后一步了,直接返回 1(递归的终止条件) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 二叉树的节点 | |
*/ | |
class BinaryTreeNode { | |
int data; | |
BinaryTreeNode left; | |
BinaryTreeNode right; | |
} | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Random; | |
import java.util.Scanner; | |
class BinarySearchTreeNode { | |
public int data; | |
public BinarySearchTreeNode left; | |
public BinarySearchTreeNode right; | |
} | |
class BinarySearchTree { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.Scanner; | |
class LinearSearch { | |
/** | |
* 线性搜索 | |
* @param list 要搜索的数组 | |
* @param target 要搜索的目标 | |
* @return 目标在数组中的索引,如果不存在则返回 -1 | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.FileWriter; | |
import java.util.ArrayList; | |
import java.util.Scanner; | |
class NoElementExceptionInStackException extends RuntimeException { | |
public NoElementExceptionInStackException() { | |
super("No element in stack to pop"); | |
} | |
} |
OlderNewer