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
/** | |
* 二叉树的节点 | |
*/ | |
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.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
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.ArrayList; | |
import java.util.Collections; | |
public class Main { | |
/** | |
* 合并两个有序数组 | |
* @param list1 第一个有序数组 | |
* @param list2 第二个有序数组 | |
* @return 合并后的有序数组 | |
*/ |
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
package org.qianq.examples; | |
import java.util.ArrayList; | |
import java.util.Scanner; | |
class LinearSearch { | |
/** | |
* 线性搜索 | |
* @param list 要搜索的数组 | |
* @param target 要搜索的目标 |
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
package org.qianq.examples; | |
import java.util.ArrayList; | |
class BubbleSort { | |
/** | |
* 冒泡排序 | |
* @param list 要排序的数组 | |
*/ | |
public static ArrayList<Integer> sort(ArrayList<Integer> list) { |
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
// 编写一个程序,维护一个有序链表。允许用户输入任意数量的想输入的整数,并将其插入链表,在插入的同时维持链表元素从小到大的排序。 | |
package org.qianq; | |
import java.util.Scanner; | |
class Node { | |
int data; | |
Node next; | |
} |
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
package org.qianq; | |
import java.io.File; | |
import java.io.FileWriter; | |
import java.io.IOException; | |
import java.util.ArrayList; | |
import java.util.Scanner; | |
/** | |
* A company that has a name and a balance. |
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
package org.qianq; | |
import java.util.ArrayList; | |
import java.util.InputMismatchException; | |
import java.util.Scanner; | |
/** | |
* An enum containing several brands of planes. | |
*/ | |
enum PlaneBrands { |
NewerOlder