Showing preview only (1,097K chars total). Download the full file or copy to clipboard to get everything.
Repository: shijiebei2009/Algorithms
Branch: master
Commit: 7cc1f17734b3
Files: 62
Total size: 624.7 KB
Directory structure:
gitextract_90z__jgc/
├── .gitignore
├── .travis.yml
├── LICENSE
├── README.md
├── pom.xml
└── src/
└── main/
├── java/
│ └── cn/
│ └── codepub/
│ ├── algorithms/
│ │ ├── arrays/
│ │ │ └── PrintArray.java
│ │ ├── commons/
│ │ │ ├── ConversionOfNumberSystems.java
│ │ │ ├── MajorityNumber.java
│ │ │ ├── MaximumProduct.java
│ │ │ └── TopK.java
│ │ ├── graph/
│ │ │ ├── Dijkstra.java
│ │ │ ├── DirectedGraphByAdjacencyList.java
│ │ │ ├── DirectedGraphByAdjacencyMatrix.java
│ │ │ ├── FloydWarshall.java
│ │ │ ├── Kruskal.java
│ │ │ ├── Prim.java
│ │ │ ├── UndirectedGraphByAdjacencyList.java
│ │ │ ├── UndirectedGraphByAdjacencyMatrix.java
│ │ │ └── utils/
│ │ │ └── UnionFindSet.java
│ │ ├── matrix/
│ │ │ └── Matrix.java
│ │ ├── multithread/
│ │ │ └── ThreadSynchronization.java
│ │ ├── queue/
│ │ │ └── PriorityApp.java
│ │ ├── similarity/
│ │ │ └── cilin/
│ │ │ └── WordSimilarity.java
│ │ ├── sorting/
│ │ │ ├── BubbleSort.java
│ │ │ ├── InsertSort.java
│ │ │ ├── QuickSort.java
│ │ │ ├── SelectionSort.java
│ │ │ └── ShellSort.java
│ │ ├── spelling/
│ │ │ └── ChineseToSpelling.java
│ │ ├── stack/
│ │ │ ├── BracketsApp.java
│ │ │ ├── CheckStackSequence.java
│ │ │ ├── InfixApp.java
│ │ │ ├── MinStack.java
│ │ │ └── PostfixApp.java
│ │ ├── strings/
│ │ │ ├── BinarySearch.java
│ │ │ ├── Combination.java
│ │ │ ├── JaccardSimilarityCoefficient.java
│ │ │ ├── LCS.java
│ │ │ ├── LCS2.java
│ │ │ ├── LCS3.java
│ │ │ ├── LevenshteinDistance.java
│ │ │ ├── LongestDecreasingSubSequence.java
│ │ │ ├── Manacher.java
│ │ │ ├── PatternStringMatch.java
│ │ │ ├── Permutation.java
│ │ │ ├── ReverseString.java
│ │ │ └── StringSort.java
│ │ ├── trees/
│ │ │ ├── DepthFirstTraversal.java
│ │ │ ├── GetPathsBySum.java
│ │ │ ├── LevelTraverseBinaryTree.java
│ │ │ ├── TraverseBinaryTree.java
│ │ │ └── VerifySequenceOfBST.java
│ │ └── utils/
│ │ ├── StackX.java
│ │ └── Tree.java
│ └── patterns/
│ ├── core/
│ │ ├── DeepClone.java
│ │ └── Singleton.java
│ └── proxy/
│ ├── CGLibProxyHandler.java
│ ├── CountImpl.java
│ ├── JDKProxyHandler.java
│ └── StaticProxyHandler.java
└── resources/
├── cilin.txt
└── log4j2.xml
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
/.idea/
Algorithms.iml
/target/
================================================
FILE: .travis.yml
================================================
language: java
jdk:
- oraclejdk8
================================================
FILE: LICENSE
================================================
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright http://codepub.cn
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
================================================
FILE: README.md
================================================
Algorithms [](https://travis-ci.org/shijiebei2009/Algorithms) [](https://www.apache.org/licenses/LICENSE-2.0.html)
==========
Algorithms playground for common questions solved in Java syntax.
This repository contains my solution for some common algorithms. I've created this repository to learn about algorithms and improve solving different common computer science problems. I'll try to add more solutions if I have time :)
Each solved problem has a program written in Java. Every solution is tested and some problems contains more than one solution with different implementations.
You can check the solution executing tests inside tests directory. Some of this problems have been resolved using TDD.
Problems
--------
### Arrays
* [Clockwise print array - 顺时针打印数组](src/main/java/cn/codepub/algorithms/arrays/PrintArray.java)
### Commons
* [Hex conversion utility - 进制转换工具](src/main/java/cn/codepub/algorithms/commons/ConversionOfNumberSystems.java)
* [Majority number - 大多数,超过一半的数](src/main/java/cn/codepub/algorithms/commons/MajorityNumber.java)
* [Maximum product - 最大乘积](src/main/java/cn/codepub/algorithms/commons/MaximumProduct.java)
* [TOPK algorithm - TOPK算法](src/main/java/cn/codepub/algorithms/commons/TopK.java)
### Graph
* [Dijkstra algorithm - 迪杰斯特拉算法](src/main/java/cn/codepub/algorithms/graph/Dijkstra.java)
* [Directed graph depth first and breadth-first by adjacency table - 邻接表实现有向图深度优先和广度优先](src/main/java/cn/codepub/algorithms/graph/DirectedGraphByAdjacencyList.java)
* [Directed graph depth first and breadth-first by adjacency matrix - 邻接矩阵实现有向图深度优先和广度优先](src/main/java/cn/codepub/algorithms/graph/DirectedGraphByAdjacencyMatrix.java)
* [Floyd warshall - 弗洛伊德算法](src/main/java/cn/codepub/algorithms/graph/FloydWarshall.java)
* [Kruskal - 克鲁斯卡尔算法](src/main/java/cn/codepub/algorithms/graph/Kruskal.java)
* [Prim - 普里姆算法](src/main/java/cn/codepub/algorithms/graph/Prim.java)
* [Undirected graph depth first and breadth-first by adjacency table - 邻接表实现无向图深度优先和广度优先](src/main/java/cn/codepub/algorithms/graph/UndirectedGraphByAdjacencyList.java)
* [Undirected graph depth first and breadth-first by adjacency matrix - 邻接矩阵实现无向图深度优先和广度优先](src/main/java/cn/codepub/algorithms/graph/UndirectedGraphByAdjacencyMatrix.java)
### Matrix
* [Matrix multiplication - 方阵乘法](src/main/java/cn/codepub/algorithms/matrix/Matrix.java)
### Multithread
* [Thread synchronization - 线程同步](src/main/java/cn/codepub/algorithms/multithread/ThreadSynchronization.java)
### Queue
* [Simple priority queue - 简单的优先级队列](src/main/java/cn/codepub/algorithms/queue/PriorityApp.java)
### Similarity
* [Words similarity by Tongyici CiLin - 基于同义词词林的词语相似度](src/main/java/cn/codepub/algorithms/similarity/cilin/WordSimilarity.java)
### Sorting Algorithm
* [Bubble sort - 冒泡排序](src/main/java/cn/codepub/algorithms/sorting/BubbleSort.java)
* [Insertion sort - 插入排序](src/main/java/cn/codepub/algorithms/sorting/InsertSort.java)
* [Quick sort - 快速排序](src/main/java/cn/codepub/algorithms/sorting/QuickSort.java)
* [Selection sort - 选择排序](src/main/java/cn/codepub/algorithms/sorting/SelectionSort.java)
* [Shell sort - 希尔排序](src/main/java/cn/codepub/algorithms/sorting/ShellSort.java)
### Chinese to Spelling
* [Chinese to spelling - 中文转拼音](src/main/java/cn/codepub/algorithms/spelling/ChineseToSpelling.java)
### Stack
* [Analyzing brackets match - 判断括号是否匹配](src/main/java/cn/codepub/algorithms/stack/BracketsApp.java)
* [Check stack sequence - 检查栈的弹出序列](src/main/java/cn/codepub/algorithms/stack/CheckStackSequence.java)
* [Infix expression turn to postfix expression - 中缀表达式转后缀表达式](src/main/java/cn/codepub/algorithms/stack/InfixApp.java)
* [Maintain a minimum number of stacks - 保持最小数的栈](src/main/java/cn/codepub/algorithms/stack/MinStack.java)
* [Postfix expression evaluation - 后缀表达式求值](src/main/java/cn/codepub/algorithms/stack/PostfixApp.java)
### Strings
* [Binary search - 二分查找](src/main/java/cn/codepub/algorithms/strings/BinarySearch.java)
* [Combination - 组合](src/main/java/cn/codepub/algorithms/strings/Combination.java)
* [Jaccard similarity coefficient - 杰卡德相似度系数](src/main/java/cn/codepub/algorithms/strings/JaccardSimilarityCoefficient.java)
* [Longest common subsequence - 最长公共子序列](src/main/java/cn/codepub/algorithms/strings/LCS.java)
* [Longest common substring 1 - 最长公共子串1](src/main/java/cn/codepub/algorithms/strings/LCS2.java)
* [Longest common substring 2 - 最长公共子串2](src/main/java/cn/codepub/algorithms/strings/LCS3.java)
* [Levenshtein distance - 编辑距离](src/main/java/cn/codepub/algorithms/strings/LevenshteinDistance.java)
* [Longest decreasing subsequence - 最长递减子序列](src/main/java/cn/codepub/algorithms/strings/LongestDecreasingSubSequence.java)
* [Pattern string match - 模式串查找](src/main/java/cn/codepub/algorithms/strings/PatternStringMatch.java)
* [Permutation - 全排列](src/main/java/cn/codepub/algorithms/strings/Permutation.java)
* [Reverse string - 反转字符串](src/main/java/cn/codepub/algorithms/strings/ReverseString.java)
* [Lexicographical - 字典序排序](src/main/java/cn/codepub/algorithms/strings/StringSort.java)
* [Manacher algorithms - 最长回文字符串](src/main/java/cn/codepub/algorithms/strings/Manacher.java)
### Trees
* [Depth-first traversal of a binary tree - 二叉树的深度优先遍历](src/main/java/cn/codepub/algorithms/trees/DepthFirstTraversal.java)
* [Get all path by given a number - 二叉树中结点值的和为输入整数的所有路径](src/main/java/cn/codepub/algorithms/trees/GetPathsBySum.java)
* [Level binary tree traversal - 二叉树的层次遍历](src/main/java/cn/codepub/algorithms/trees/LevelTraverseBinaryTree.java)
* [Binary tree traversal - 二叉树的遍历](src/main/java/cn/codepub/algorithms/trees/TraverseBinaryTree.java)
* [Verify sequence Of binary search tree - 验证二叉搜索树序列](src/main/java/cn/codepub/algorithms/trees/VerifySequenceOfBST.java)
### Design Patterns
* [Deep clone - 深拷贝](src/main/java/cn/codepub/patterns/core/DeepClone.java)
* [Singleton - 单例](src/main/java/cn/codepub/patterns/core/Singleton.java)
* [Static proxy - 静态代理](src/main/java/cn/codepub/patterns/proxy/StaticProxyHandler.java)
* [JDK dynamic proxy - JDK实现动态代理](src/main/java/cn/codepub/patterns/proxy/JDKProxyHandler.java)
* [CGLib dynamic proxy - CGLib实现动态代理](src/main/java/cn/codepub/patterns/proxy/CGLibProxyHandler.java)
Author
------------
* Developed By [Xu Wang](http://codepub.cn)
License
-------
Copyright 2015 Xu Wang
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
================================================
FILE: pom.xml
================================================
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cn.codepub</groupId>
<artifactId>algorithms</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<version.commons.io>2.7</version.commons.io>
<version.junit>4.13.1</version.junit>
<version.commons.lang3>3.4</version.commons.lang3>
<version.log4j>2.17.1</version.log4j>
<version.jdk>1.8</version.jdk>
<version.lombok>1.16.12</version.lombok>
<version.guava>20.0</version.guava>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<compilerVersion>${version.jdk}</compilerVersion>
<source>${version.jdk}</source>
<target>${version.jdk}</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${version.commons.io}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${version.junit}</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${version.commons.lang3}</version>
</dependency>
<dependency>
<groupId>com.github.stuxuhai</groupId>
<artifactId>jpinyin</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${version.log4j}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${version.log4j}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${version.lombok}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${version.guava}</version>
</dependency>
</dependencies>
</project>
================================================
FILE: src/main/java/cn/codepub/algorithms/arrays/PrintArray.java
================================================
package cn.codepub.algorithms.arrays;
import java.util.ArrayList;
import java.util.List;
/**
* <p>
* Created with IntelliJ IDEA. 2015/10/29 21:29
* </p>
* <p>
* ClassName:PrintArray
* </p>
* <p>
* Description:顺时针打印二位数组
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class PrintArray {
static int nums[][];
static List<Integer> list = new ArrayList<>();
public static void main(String[] args) {
nums = new int[][]{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}, {16, 17, 18, 19, 20}, {21, 22, 23, 24, 25}};
moveRight(0, 0, nums.length, nums[0].length, 0, nums.length * nums[0].length);
System.out.println(list);
list.clear();
nums = new int[][]{{1}, {2}};
moveRight(0, 0, nums.length, nums[0].length, 0, nums.length * nums[0].length);
System.out.println(list);
list.clear();
}
private static void moveRight(int curRow, int curCol, int rows, int cols, int temp, int size) {
if (size <= 0) {
return;
}
if (curCol + 1 < cols - temp) {
list.add(nums[curRow][curCol]);
curCol++;
size--;
moveRight(curRow, curCol, rows, cols, temp, size);
} else {
moveDown(curRow, curCol--, rows, cols, temp, size);
}
}
private static void moveDown(int curRow, int curCol, int rows, int cols, int temp, int size) {
if (size <= 0) {
return;
}
if (curRow + 1 < rows - temp) {
list.add(nums[curRow][curCol]);
size--;
curRow++;
moveDown(curRow, curCol, rows, cols, temp, size);
} else {
moveLeft(curRow--, curCol, rows, cols, temp, size);
}
}
private static void moveLeft(int curRow, int curCol, int rows, int cols, int temp, int size) {
if (size <= 0) {
return;
}
if (curCol - 1 >= temp - 1) {
list.add(nums[curRow][curCol]);
size--;
curCol--;
moveLeft(curRow, curCol, rows, cols, temp, size);
} else {
moveUp(curRow, ++curCol, rows, cols, temp + 1, size);
}
}
private static void moveUp(int curRow, int curCol, int rows, int cols, int temp, int size) {
if (size <= 0) {
return;
}
if (curRow - 1 > temp - 1) {
curRow--;
list.add(nums[curRow][curCol]);
size--;
moveUp(curRow, curCol, rows, cols, temp, size);
} else {
moveRight(curRow, ++curCol, rows, cols, temp, size);
}
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/commons/ConversionOfNumberSystems.java
================================================
package cn.codepub.algorithms.commons;
import org.junit.Assert;
import org.junit.Test;
/**
* <p>
* Created with IntelliJ IDEA. 2015/12/12 15:35
* </p>
* <p>
* ClassName:ConversionOfNumberSystems
* </p>
* <p>
* Description:任意进制位转换系统
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class ConversionOfNumberSystems {
/**
* 第一种方法
*
* @param number 需要进行进制转换的数字
* @param base 需要转为几进制
* @return
*/
public static String conversion(int number, int base) {
StringBuilder sb = new StringBuilder();
while (number > 0) {
int i = number % base;
switch (i) {
case 11:
sb.append("A");
break;
case 12:
sb.append("B");
break;
case 13:
sb.append("C");
break;
case 14:
sb.append("D");
break;
case 15:
sb.append("E");
break;
default:
sb.append(i);
}
number /= base;
}
return sb.reverse().toString();
}
/**
* 第二种方法
*
* @param num 需要转换进制的数字
* @param base 需要转成几进制
* @return 转换结果
*/
public static String baseString(int num, int base) {
String str, digit = "0123456789abcdef";
if (num == 0) {
return "";
} else {
str = baseString(num / base, base);
return str + digit.charAt(num % base);
}
}
@Test
public void test() {
System.out.println(conversion(1024, 16));
System.out.println(baseString(1024, 16));
Assert.assertEquals(conversion(1024, 16), baseString(1024, 16));
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/commons/MajorityNumber.java
================================================
package cn.codepub.algorithms.commons;
import java.util.ArrayList;
/**
* <p>
* Created with IntelliJ IDEA. 2015/10/22 11:00
* </p>
* <p>
* ClassName:MajorityNumber
* </p>
* <p>
* Description:获取某个出现次数超过一半的元素
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class MajorityNumber {
public static void main(String[] args) {
int[] nums = new int[]{1, 2, 3, 2, 2, 4, 2, 5, 8, 2};
ArrayList<Integer> a = new ArrayList<Integer>();
for (int i : nums) {
a.add(i);
}
System.out.println(new MajorityNumber().majorityNumber(a));
}
public int majorityNumber(ArrayList<Integer> nums) {
int candidate1 = 0, candidate2 = 0;
int count1, count2;
count1 = count2 = 0;
for (int i = 0; i < nums.size(); i++) {
if (candidate1 == nums.get(i)) {
count1++;
} else if (candidate2 == nums.get(i)) {
count2++;
} else if (count1 == 0) {
candidate1 = nums.get(i);
count1 = 1;
} else if (count2 == 0) {
candidate2 = nums.get(i);
count2 = 1;
} else {
count1--;
count2--;
}
}
count1 = count2 = 0;
for (int i = 0; i < nums.size(); i++) {
if (nums.get(i) == candidate1) {
count1++;
} else if (nums.get(i) == candidate2) {
count2++;
}
}
return count1 > count2 ? candidate1 : candidate2;
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/commons/MaximumProduct.java
================================================
package cn.codepub.algorithms.commons;
import org.junit.Test;
/**
* <p>
* Created with IntelliJ IDEA. 15/12/17 16:53
* </p>
* <p>
* ClassName:MaximumProduct(最大乘积)
* </p>
* <p>
* Description:输入n个元素组成的序列S,你需要找出一个乘积最大的连续子序列。如果这个最大的乘积不是正数,应输出0表示无解。
* 1<=n<=18:表示不超过18个元素
* -10<=Si<=10:表示每个元素的绝对值不大于10
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class MaximumProduct {
/**
* 连续子序列必有开始和结束,所以采用暴力破解法,枚举开始元素和结束元素
*
* @param arrs
* @return 最大乘积结果
*/
public static long getMaximumProduct(long[] arrs) {
long max = 0;
//以i作为开始,以j作为结束
for (int i = 0; i < arrs.length - 1; i++) {
for (int j = i + 1; j < arrs.length; j++) {
long temp = 1;
for (int k = i; k <= j; k++) {
temp *= arrs[k];
}
if (temp > max) {
max = temp;
}
}
}
return max;
}
@Test
public void test() {
long[] arr = new long[]{2, 4, -3};
long maximumProduct = getMaximumProduct(arr);
System.out.println(maximumProduct);
arr = new long[]{2, 5, -1, 2, -1};
maximumProduct = getMaximumProduct(arr);
System.out.println(maximumProduct);
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/commons/TopK.java
================================================
package cn.codepub.algorithms.commons;
import org.junit.Test;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
/**
* <p>
* Created with IntelliJ IDEA. 15/12/17 11:03
* </p>
* <p>
* ClassName:TopK
* </p>
* <p>
* Description:思考利用JDK的PriorityQueue实现TopK问题,TopK问题说的是:输入n个整数,输出其中最小的k个
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class TopK {
private static Queue<Integer> queue;
/**
* 从n个整数中查找最小的k个
*
* @param n
* @param k
* @return
*/
public static boolean getTopK(int n, int k) {
queue = new PriorityQueue<>(k, new Comparator<Integer>() {
@Override
public int compare(Integer o1, Integer o2) {
return o2.compareTo(o1);
}
});
if (n < k) {
System.err.println("输入的n和k不合法!");
return false;
}
Random random = new Random();
//先加入k个再说
for (int i = 0; i < k; i++) {
queue.add(random.nextInt());
}
//这个时候,队列已满,若再想加入,那么必须是比队列中最大的元素小的才可以加入
for (int i = k; i < n; i++) {
int i1 = random.nextInt();
if (queue.peek() > i1) {
queue.poll();
queue.add(i1);
}
}
return true;
}
/**
* 因为队列是一个大根堆,所以如果想从小到大输出的话,需要借助其它方式,最简单的是利用递归同样可以实现
*
* @param queue
*/
public static void printTopK(Queue queue) {
if (!queue.isEmpty()) {
Object remove = queue.remove();
printTopK(queue);
System.out.println(remove);
}
}
@Test
public void test() {
boolean topK = getTopK(5, 10);
if (topK) {
printTopK(queue);
}
topK = getTopK(100, 100);
if (topK) {
printTopK(queue);
}
topK = getTopK(10000, 10);
if (topK) {
printTopK(queue);
}
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/graph/Dijkstra.java
================================================
package cn.codepub.algorithms.graph;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Queue;
/**
* <p>
* Created with IntelliJ IDEA. 2015/12/14 10:06
* </p>
* <p>
* ClassName:Dijkstra
* </p>
* <p>
* Description:使用迪杰斯特拉算法解决单源最短路径
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class Dijkstra {
//顶点数组
public Vertex[] vertexes;
//顶点类
class Vertex {
char name;//顶点名称
Edge firstEdge;//顶点所连的第一条边
public Vertex(char name) {
this.name = name;
}
}
//边类
class Edge {
Vertex endVertex;//边所连的末尾节点
int value;//边的权值,注意使用迪杰斯特拉不允许权值为负值
Edge next = null;//该边的起点所连的另一头边,采用邻接表结构存储
public Edge(int value) {
this.value = value;
}
}
@org.junit.Test
public void create() {
//构造图
Edge edge2 = new Edge(2);
Edge edge3 = new Edge(3);
Edge edge1 = new Edge(1);
Edge edge4 = new Edge(4);
Edge edge8 = new Edge(8);
Edge edge7 = new Edge(7);
Edge edge5 = new Edge(5);
Vertex v0 = new Vertex('0');
Vertex v1 = new Vertex('1');
Vertex v2 = new Vertex('2');
Vertex v3 = new Vertex('3');
Vertex v4 = new Vertex('4');
edge2.next = edge4;
edge2.endVertex = v1;
edge4.endVertex = v4;
v0.firstEdge = edge2;
edge3.endVertex = v2;
v1.firstEdge = edge3;
edge1.next = edge5;
edge1.endVertex = v4;
edge5.endVertex = v3;
v2.firstEdge = edge1;
edge7.endVertex = v3;
v4.firstEdge = edge7;
edge8.endVertex = v0;
v3.firstEdge = edge8;
vertexes = new Vertex[]{v0, v1, v2, v3, v4};
//寻找最短路径数组
Dijkstra.getShortestPath(vertexes);
}
/**
* 求得单源最短路径
*
* @param vertexes
*/
public static void getShortestPath(Vertex[] vertexes) {
int[] dist = new int[vertexes.length];
char[] pred = new char[vertexes.length];
Queue<Vertex> queue = new ArrayDeque<>();
for (int i = 0; i < vertexes.length; i++) {
dist[i] = Integer.MAX_VALUE;
pred[i] = '-';
}
dist[0] = 0;//表示源到源自身为0
pred[0] = '0';
//通常情况下,是按照优先级高低插入队列,而优先级高低的衡量标准是离源点距离的远近,但是此并不为必要条件,所以你可以以其它顺序插入队列
//以v0,v1,v2,v3,v4的顺序插入队列
//for (int i = 0; i < vertexes.length; i++) {
// queue.add(vertexes[i]);
//}
//以v0,v1,v4,v2,v3的顺序插入队列
queue.add(vertexes[0]);
queue.add(vertexes[1]);
queue.add(vertexes[4]);
queue.add(vertexes[2]);
queue.add(vertexes[3]);
System.out.println(Arrays.toString(dist));
for (Vertex v : queue) {
System.out.print("顶点数组为:" + v.name + "\t");
}
System.out.println();
while (!queue.isEmpty()) {
Vertex vertex = queue.remove();
// Graph.Vertex vertex = queue.peek();
int u = getNo(vertexes, vertex.name);
if (-1 == u) {
System.err.println("该顶点不存在:" + vertex.name);
break;
}
Edge firstEdge = vertex.firstEdge;
while (firstEdge != null) {
int w = firstEdge.value;//获取边的权值
int v = getNo(vertexes, firstEdge.endVertex.name);
if (-1 == v) {
System.err.println("该顶点不存在:" + firstEdge.endVertex.name);
}
int newW = dist[u] + w;
if (newW < 0) {
newW = Integer.MAX_VALUE;//如果溢出,需要重新置为最大整数值,原因是:最大整数值加任意大于0的值就会溢出,变为最小正整数值
}
if (newW < dist[v]) {
System.out.print("(" + "0" + "," + vertex.name + ")" + "+" + "(" + vertex.name + "," + firstEdge.endVertex.name + ")" + "<" + "" +
"(0," +
firstEdge
.endVertex
.name + ")");
System.out.println("\t更新距离数组\t" + "(0," + firstEdge.endVertex.name + ")=" + newW);
dist[v] = newW;
pred[v] = vertex.name;
} else {
System.out.println("(" + "0" + "," + vertex.name + ")" + "+" + "(" + vertex.name + "," + firstEdge.endVertex.name + ")" + ">" +
"" +
"(0," +
firstEdge
.endVertex
.name + ")");
}
firstEdge = firstEdge.next;
}
}
System.out.println("距离数组为:" + Arrays.toString(dist));
//注意,最终的最短路径可以经过pred数组推导出来,很简单
System.out.println("路径数组为:" + Arrays.toString(pred));
}
/**
* 根据节点的名称返回节点在数组中的序号
*
* @param vertexes
* @param name
* @return
*/
private static int getNo(Vertex[] vertexes, char name) {
for (int i = 0; i < vertexes.length; i++) {
if (vertexes[i].name == name) {
return i;
}
}
return -1;
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/graph/DirectedGraphByAdjacencyList.java
================================================
package cn.codepub.algorithms.graph;
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;
/**
* <p>
* Created with IntelliJ IDEA. 2015/12/2 20:33
* </p>
* <p>
* ClassName:UndirectedGraphByAdjacencyList
* </p>
* <p>
* Description:使用邻接表实现的无向图深度优先及广度优先
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class DirectedGraphByAdjacencyList {
public static void main(String[] args) {
DirectedGraphByAdjacencyList undirectedGraphAdjacencyList = new DirectedGraphByAdjacencyList();
undirectedGraphAdjacencyList.createGraph();
undirectedGraphAdjacencyList.depthFirstSearch();
undirectedGraphAdjacencyList.breadthFirstSearch();
}
private void breadthFirstSearch() {
boolean visited[] = new boolean[vertexes.length];
Queue<Integer> queue = new ArrayDeque();
System.out.println("\nBreadth First Search:");
for (int i = 0; i < vertexes.length; i++) {
if (!visited[i]) {
queue.add(i);
}
while (!queue.isEmpty()) {
Integer remove = queue.remove();
if (!visited[remove]) {
String data = vertexes[remove].data;
System.out.print(data + "\t");
visited[remove] = true;
}
Edge firstEdge = vertexes[remove].firstEdge;
while (firstEdge != null) {
if (!visited[firstEdge.vertex]) {
queue.add(firstEdge.vertex);
}
firstEdge = firstEdge.nextEdge;
}
}
}
}
public void depthFirstSearch() {
System.out.println("\nDepth First Search:");
boolean[] visited = new boolean[vertexes.length];
for (int i = 0; i < vertexes.length; i++) {
if (!visited[i]) {
depthFirstSearch(visited, i);
}
}
}
private void depthFirstSearch(boolean[] visited, int i) {
System.out.print(vertexes[i].data + "\t");
visited[i] = true;
Edge firstEdge = vertexes[i].firstEdge;
while (firstEdge != null) {
if (!visited[firstEdge.vertex]) {
depthFirstSearch(visited, firstEdge.vertex);
}
firstEdge = firstEdge.nextEdge;
}
}
//邻接表中边对应的链表的顶点
private class Edge {
int vertex;//该边所指向顶点的位置
Edge nextEdge;//指向下一条弧的指针
}
//邻接表中表的顶点
private class Vertex {
String data;//顶点信息
Edge firstEdge;//指向第一条依附该顶点的弧
}
private Vertex[] vertexes;//顶点数组
/**
* 根据用户输入构造图
*/
public void createGraph() {
Scanner scanner = new Scanner(System.in);
System.out.println("please input vertex number:");
int vertexNum = scanner.nextInt();
System.out.println("please input edge number:");
int edgeNum = scanner.nextInt();
//无向图有n个顶点,最多有n*(n-1)/2条边
// vertex: n = > edge: (n-1)*n/2
if (vertexNum < 1 || edgeNum < 1 || edgeNum > (vertexNum - 1) * vertexNum / 2) {
System.err.println("input error, invalid vertex or edges!");
return;
}
//init vertex and edges
vertexes = new Vertex[vertexNum];
System.out.println("input the vertex by space:");
for (int i = 0; i < vertexNum; i++) {
vertexes[i] = new Vertex();
vertexes[i].data = scanner.next();
vertexes[i].firstEdge = null;
}
System.out.println("input the edge between vertex by pair:");
for (int i = 0; i < edgeNum; i++) {
String v1 = scanner.next();
String v2 = scanner.next();
int start = getPosition(v1);
int end = getPosition(v2);
if (start == -1 || end == -1) {
System.err.println(v1 + " or " + v2 + " are invalid!");
}
if (vertexes[start].firstEdge == null) {
Edge edge = new Edge();
edge.vertex = end;
edge.nextEdge = null;
vertexes[start].firstEdge = edge;
} else {
Edge firstEdge = vertexes[start].firstEdge;
while (firstEdge.nextEdge != null) {
firstEdge = firstEdge.nextEdge;
}
Edge edge = new Edge();
edge.vertex = end;
edge.nextEdge = null;
firstEdge.nextEdge = edge;
}
}
System.out.println("打印顶点如下:");
for (int i = 0; i < vertexes.length; i++) {
String data = vertexes[i].data;
System.out.print(data + "\t");
}
System.out.println("\n打印边的邻接表如下:");
for (int i = 0; i < vertexes.length; i++) {
Edge firstEdge = vertexes[i].firstEdge;
System.out.print(vertexes[i].data);
while (firstEdge != null) {
System.out.print("--" + vertexes[firstEdge.vertex].data);
firstEdge = firstEdge.nextEdge;
}
System.out.print("\t");
}
}
private int getPosition(String v1) {
for (int i = 0; i < vertexes.length; i++) {
if (vertexes[i].data.equals(v1)) {
return i;
}
}
return -1;
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/graph/DirectedGraphByAdjacencyMatrix.java
================================================
package cn.codepub.algorithms.graph;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Queue;
import java.util.Scanner;
/**
* <p>
* Created with IntelliJ IDEA. 2015/12/3 22:15
* </p>
* <p>
* ClassName:DirectedGraphByAdjacencyMatrix
* </p>
* <p>
* Description:使用邻接矩阵实现有向图的深度优先及广度优先
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class DirectedGraphByAdjacencyMatrix {
private String[] vertex;//顶点集合
private int[][] edges;//边的集合
public static void main(String[] args) {
DirectedGraphByAdjacencyMatrix directedGraphByAdjacencyMatrix = new DirectedGraphByAdjacencyMatrix();
directedGraphByAdjacencyMatrix.createGraph();
directedGraphByAdjacencyMatrix.depthFirstSearch();
directedGraphByAdjacencyMatrix.breadthFirstSearch();
}
public void breadthFirstSearch() {
//设置访问标记数组
System.out.println("\nBreadth First Search:");
boolean[] visited = new boolean[vertex.length];
Queue<Integer> queue = new ArrayDeque<>();
for (int i = 0; i < vertex.length; i++) {
if (!visited[i]) {
System.out.print(vertex[i] + "\t");
queue.add(i);
visited[i] = true;
}
while (!queue.isEmpty()) {
int remove = queue.remove();
int count = 0;
for (int j = getNextVertex(remove, count); j >= 0; j = getNextVertex(remove, count)) {
if (!visited[j]) {
visited[j] = true;
System.out.print(vertex[j] + "\t");
queue.add(j);
} else {
count++;
}
}
}
}
}
/**
* 寻找与当前点有边相连的下一个顶点
*
* @param row 查找该行
* @param col 从该列开始查找
* @return
*/
private int getNextVertex(int row, int col) {
for (int j = col; j < edges[row].length; j++) {
if (edges[row][j] == 1) {
return j;
}
}
return -1;
}
/**
* 根据用户输入构造图
*/
public void createGraph() {
Scanner scanner = new Scanner(System.in);
System.out.println("please input vertex number:");
int vertexNum = scanner.nextInt();
System.out.println("please input edge number:");
int edgeNum = scanner.nextInt();
//无向图有n个顶点,最多有n*(n-1)/2条边
// vertex: n = > edge: (n-1)*n/2
if (vertexNum < 1 || edgeNum < 1 || edgeNum > (vertexNum - 1) * vertexNum / 2) {
System.err.println("input error, invalid vertex or edges!");
return;
}
//init vertex and edges
vertex = new String[vertexNum];
edges = new int[vertexNum][vertexNum];
System.out.println("input the vertex by space:");
for (int i = 0; i < vertexNum; i++) {
vertex[i] = scanner.next();
}
System.out.println("input the edge between vertex by pair:");
for (int i = 0; i < edgeNum; i++) {
String v1 = scanner.next();
String v2 = scanner.next();
int start = getPosition(v1);
int end = getPosition(v2);
if (start == -1 || end == -1) {
System.err.println(v1 + " or " + v2 + " are invalid!");
}
//更新边的邻接矩阵
edges[start][end] = 1;
}
System.out.println("打印顶点如下:" + Arrays.toString(vertex));
System.out.println("打印边的邻接矩阵如下:");
for (int temp[] : edges) {
System.out.println(Arrays.toString(temp));
}
}
/**
* 对外暴露的调用接口
*/
public void depthFirstSearch() {
//设置访问标记数组
boolean[] visited = new boolean[vertex.length];
System.out.println("Depth First Search:");
for (int i = 0; i < vertex.length; i++) {
if (!visited[i]) {
depthFirstSearch(visited, i);
}
}
}
/**
* 内部递归的深度优先实现
*
* @param visited
* @param i
*/
private void depthFirstSearch(boolean[] visited, int i) {
visited[i] = true;
System.out.print(vertex[i] + "\t");
int count = 0;
for (int j = getNextVertex(i, count); j >= 0; j = getNextVertex(i, count)) {
if (!visited[j]) {
depthFirstSearch(visited, j);
} else {
count++;
}
}
}
/**
* 返回顶点在集合中的位置
*
* @param s
* @return
*/
public int getPosition(String s) {
for (int i = 0; i < vertex.length; i++) {
if (vertex[i].equalsIgnoreCase(s)) {
return i;
}
}
return -1;
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/graph/FloydWarshall.java
================================================
package cn.codepub.algorithms.graph;
import java.util.Arrays;
/**
* <p>
* Created with IntelliJ IDEA. 2015/12/14 15:45
* </p>
* <p>
* ClassName:FloydWarshall
* </p>
* <p>
* Description:使用弗洛伊德算法求所有点对最短路径,而弗洛伊德的核心就是用动态规划
* 动态规划有两个令人激动的特性:它专注解决较小的,有条件限制的问题。当限制条件很严格时,函数将会非常简单,系统地松弛限制条件,直到最后产生希望得到的结果
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class FloydWarshall {
//顶点数组
public Vertex[] vertexes;
private static char[][] pred;//路径矩阵
//顶点类
class Vertex {
char name;//顶点名称
Edge firstEdge;//顶点所连的第一条边
public Vertex(char name) {
this.name = name;
}
}
//边类
class Edge {
Vertex endVertex;//边所连的末尾节点
int value;//边的权值,注意使用迪杰斯特拉不允许权值为负值
Edge next = null;//该边的起点所连的另一头边,采用邻接表结构存储
public Edge(int value) {
this.value = value;
}
}
@org.junit.Test
public void create() {
Vertex v0 = new Vertex('0');
Vertex v1 = new Vertex('1');
Vertex v2 = new Vertex('2');
Vertex v3 = new Vertex('3');
Vertex v4 = new Vertex('4');
Edge edge2 = new Edge(2);
edge2.endVertex = v1;
Edge edge4 = new Edge(4);
edge4.endVertex = v4;
edge2.next = edge4;
v0.firstEdge = edge2;
Edge edge3 = new Edge(3);
edge3.endVertex = v2;
v1.firstEdge = edge3;
Edge edge1 = new Edge(1);
Edge edge5 = new Edge(5);
edge1.endVertex = v4;
edge5.endVertex = v3;
edge1.next = edge5;
v2.firstEdge = edge1;
Edge edge7 = new Edge(7);
edge7.endVertex = v3;
v4.firstEdge = edge7;
Edge edge8 = new Edge(8);
edge8.endVertex = v0;
v3.firstEdge = edge8;
vertexes = new Vertex[]{v0, v1, v2, v3, v4};
getShortestPathByDp(vertexes);
}
public static void getShortestPathByDp(Vertex[] vertexes) {
int size = vertexes.length;
int[][] dist = new int[size][size];
pred = new char[size][size];
for (int i = 0; i < size; i++) {
int j = 0;
for (; j < size; j++) {
dist[i][j] = Integer.MAX_VALUE;
pred[i][j] = '-';
}
dist[i][i] = 0;
Edge firstEdge = vertexes[i].firstEdge;
while (firstEdge != null) {
int no = getNo(vertexes, firstEdge.endVertex.name);
dist[i][no] = firstEdge.value;
pred[i][no] = vertexes[i].name;
firstEdge = firstEdge.next;
}
}
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
for (int k = 0; k < size; k++) {
int newLen = dist[j][i] + dist[i][k];
if (newLen < 0) {
newLen = Integer.MAX_VALUE;//说明溢出了,那么重新置为最大整数值
}
if (newLen < dist[j][k]) {
dist[j][k] = newLen;
pred[j][k] = pred[i][k];
}
}
}
}
//dist[i][j]即表示在有向图中,从vi到vj的最短路径
for (int[] d : dist) {
System.out.println(Arrays.toString(d));
}
System.out.println("-------------------------");
for (char[] d : pred) {
System.out.println(Arrays.toString(d));
}
String s = constructShortestPath(4, 2);
System.out.println("4->2的最短路径是;" + s);
}
private static int getNo(Vertex[] vertexes, char name) {
for (int i = 0; i < vertexes.length; i++) {
if (vertexes[i].name == name) {
return i;
}
}
return -1;
}
//从已知的pred矩阵中构造出最短路径
/**
* @param start 起始点
* @param end 结束点
* @return 起始点->结束的之间的最短路径
*/
public static String constructShortestPath(int start, int end) {
StringBuilder sb = new StringBuilder();
sb.append(end + "-");
int temp = end;
while (temp != start) {
char c = pred[start][temp];
if (c == '-') {
return start + "和" + end + "之间不存在最短路径!";
}
temp = Integer.valueOf(String.valueOf(c));
sb.append(temp + "-");
}
sb.deleteCharAt(sb.length() - 1);
return sb.reverse().toString();
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/graph/Kruskal.java
================================================
package cn.codepub.algorithms.graph;
import cn.codepub.algorithms.graph.utils.UnionFindSet;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Queue;
/**
* <p>
* Created with IntelliJ IDEA. 15/12/16 15:39
* </p>
* <p>
* ClassName:Kruskal
* </p>
* <p>
* Description:使用克鲁斯卡尔算法求最小生成树,该算法的核心是一个不相交集,也就是说若加入当前边不形成回路的话即合法,否则不合法
* 而实现不相交集最常用的方法就是使用并查集,借助于实现的并查集来实现克鲁斯卡尔算法
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class Kruskal {
private static List<Vertex> vertexList = new ArrayList<>();//顶点集
/**
* 实现一个匿名类,提供了基于边的权值的比较器
*/
public static final Queue<Edge> QUEUE = new PriorityQueue<>((e1, e2) -> {
if (e1.value == e2.value) {
return 0;
} else {
return e1.value > e2.value ? 1 : -1;
}
});
private static List<Edge> visitedEdges = new ArrayList<>();//已访问的边集
private static List<Edge> edgeList = new ArrayList<>();//边集
private static class Vertex {
char name;//顶点名称
public Vertex(char name) {
this.name = name;
}
@Override
public String toString() {
return String.valueOf(name);
}
}
private static class Edge {
Vertex start;//边的起始点
Vertex end;//边的终结点
int value;//边的权值
public Edge(Vertex a, Vertex b, int val) {
this.start = a;
this.end = b;
this.value = val;
}
@Override
public String toString() {
return "顶点是:" + this.start.name + "-->" + this.end.name + ",权值:" + this.value;
}
}
/**
* 添加边的函数
*
* @param a 起始点
* @param b 终结点
* @param val 边的权值
*/
public static void addEdge(Vertex a, Vertex b, int val) {
Edge edge = new Edge(a, b, val);
edgeList.add(edge);
}
public static void minimumSpanningTree() {
UnionFindSet unionFindSet = new UnionFindSet(vertexList.size());
// 加入优先级队列
QUEUE.addAll(edgeList);
// queue.addAll(edgeList.stream().collect(Collectors.toList()));
while (!QUEUE.isEmpty()) {
Edge remove = QUEUE.remove();
Vertex start = remove.start;//获取起始点
Vertex end = remove.end;//获取终结点
int startNo = getVertexNo(vertexList, start.name);//得到起点编号
int endNo = getVertexNo(vertexList, end.name);//得到终点编号
int father1 = unionFindSet.findSet(startNo);
int father2 = unionFindSet.findSet(endNo);
if (father1 != father2) {//说明两棵树不在同一棵子树
unionFindSet.union(startNo, endNo);//合并之
visitedEdges.add(remove);//将当前访问的边加入已访问列表
}
}
}
private static int getVertexNo(List<Vertex> vertexList, char name) {
for (int i = 0; i < vertexList.size(); i++) {
if (vertexList.get(i).name == name) {
return i;
}
}
return -1;
}
@Test
public void create() {
//构造图
Vertex v0 = new Vertex('0');
Vertex v1 = new Vertex('1');
Vertex v2 = new Vertex('2');
Vertex v3 = new Vertex('3');
Vertex v4 = new Vertex('4');
vertexList.add(v0);
vertexList.add(v1);
vertexList.add(v2);
vertexList.add(v3);
vertexList.add(v4);
addEdge(v0, v1, 2);
addEdge(v1, v2, 3);
addEdge(v2, v4, 1);
addEdge(v0, v4, 4);
addEdge(v0, v3, 8);
addEdge(v2, v3, 5);
addEdge(v4, v3, 7);
minimumSpanningTree();
System.out.println("使用克鲁斯卡尔算法选取的边是:");
System.out.println(visitedEdges);
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/graph/Prim.java
================================================
package cn.codepub.algorithms.graph;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
/**
* <p>
* Created with IntelliJ IDEA. 15/12/16 10:33
* </p>
* <p>
* ClassName:Prim
* </p>
* <p>
* Description:使用Prim算法实现最小生成树,注意最小生成树所使用的图是无向图,所以其存储结构应区别于有向图
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class Prim {
private static class Vertex {
char name;//顶点名称
public Vertex(char name) {
this.name = name;
}
public Vertex() {
}
@Override
public String toString() {
return String.valueOf(this.name);
}
}
private static class Edge {
Vertex start;//边的开始顶点
Vertex end;//边的结束顶点
int value;//权值
public Edge(Vertex start, Vertex end, int value) {
this.start = start;
this.end = end;
this.value = value;
}
}
private static List<Vertex> vertexList = new ArrayList<>();//节点集
private static List<Vertex> visitedVertex = new ArrayList<>();//已经访问的节点集
private static List<Edge> edgeList = new ArrayList<>();//边集合
public static void addEdge(Vertex a, Vertex b, int val) {
Edge edge = new Edge(a, b, val);
edgeList.add(edge);
}
/**
* 使用Prim算法求最小生成树
*/
public static void minimumSpanningTree() {
//随机选择第0个作为开始
visitedVertex.add(vertexList.get(0));
for (int i = 1; i < vertexList.size(); i++) {//其实并不需要遍历vertexList,需要做的只是剩余几个节点遍历几次即可,因为最终的目的是将所有的节点都加入已访问列表,而我们已经随机选择从第0个开始了,第0个已经被首先加入
int temp = Integer.MAX_VALUE;//遍历取得权值最小的边,且该边属于start和end节点
Vertex tempVertex = new Vertex();
//从已访问列表中查找边,将其作为start,寻找start和end之间满足条件的边
for (Vertex start : visitedVertex) {
for (int j = 0; j < edgeList.size(); j++) {
Edge edge = edgeList.get(j);
if (edge.start.name == start.name && !containVertex(edge.end.name)) {
//说明在start和end之间存在边,并且边的权值也可以获得
int weight = edge.value;
if (weight < temp) {
temp = weight;
tempVertex = edge.end;//如若选择该边,那么将顶点加入已访问列表
}
}
}
}
visitedVertex.add(tempVertex);
}
}
/**
* 测试当前顶点是否已加入“已访问顶点列表”
*
* @param name
* @return
*/
private static boolean containVertex(char name) {
for (int i = 0; i < visitedVertex.size(); i++) {
if (visitedVertex.get(i).name == name) {
return true;
}
}
return false;
}
@Test
public void create() {
//构造图
Vertex v0 = new Vertex('0');
Vertex v1 = new Vertex('1');
Vertex v2 = new Vertex('2');
Vertex v3 = new Vertex('3');
Vertex v4 = new Vertex('4');
vertexList.add(v0);
vertexList.add(v1);
vertexList.add(v2);
vertexList.add(v3);
vertexList.add(v4);
addEdge(v0, v1, 2);
addEdge(v1, v2, 3);
addEdge(v2, v4, 1);
addEdge(v0, v4, 4);
addEdge(v0, v3, 8);
addEdge(v2, v3, 5);
addEdge(v4, v3, 7);
minimumSpanningTree();
System.out.println(visitedVertex);
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/graph/UndirectedGraphByAdjacencyList.java
================================================
package cn.codepub.algorithms.graph;
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;
/**
* <p>
* Created with IntelliJ IDEA. 2015/12/2 20:33
* </p>
* <p>
* ClassName:UndirectedGraphByAdjacencyList
* </p>
* <p>
* Description:使用邻接表实现的无向图深度优先及广度优先
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class UndirectedGraphByAdjacencyList {
public static void main(String[] args) {
// test data following
// please input vertex number:
// 7
// please input edge number:
// 7
// input the vertex by space:
// a b c d e f g
// input the edge between vertex by pair:
// a c a d a f b c c d e g f g
// 打印顶点如下:
// a b c d e f g
// 打印边的邻接表如下:
// a--c--d--f b--c c--a--b--d d--a--c e--g f--a--g g--e--f
// Depth First Search:
// a c b d f g e
// Breadth First Search:
// a c d f b g e
// Process finished with exit code 0
UndirectedGraphByAdjacencyList undirectedGraphAdjacencyList = new UndirectedGraphByAdjacencyList();
undirectedGraphAdjacencyList.createGraph();
undirectedGraphAdjacencyList.depthFirstSearch();
undirectedGraphAdjacencyList.breadthFirstSearch();
}
private void breadthFirstSearch() {
boolean visited[] = new boolean[vertexes.length];
Queue<Integer> queue = new ArrayDeque();
System.out.println("\nBreadth First Search:");
for (int i = 0; i < vertexes.length; i++) {
if (!visited[i]) {
queue.add(i);
}
while (!queue.isEmpty()) {
Integer remove = queue.remove();
if (!visited[remove]) {
String data = vertexes[remove].data;
System.out.print(data + "\t");
visited[remove] = true;
}
Edge firstEdge = vertexes[remove].firstEdge;
while (firstEdge != null) {
if (!visited[firstEdge.vertex]) {
queue.add(firstEdge.vertex);
}
firstEdge = firstEdge.nextEdge;
}
}
}
}
public void depthFirstSearch() {
System.out.println("\nDepth First Search:");
boolean[] visited = new boolean[vertexes.length];
for (int i = 0; i < vertexes.length; i++) {
if (!visited[i]) {
depthFirstSearch(visited, i);
}
}
}
private void depthFirstSearch(boolean[] visited, int i) {
System.out.print(vertexes[i].data + "\t");
visited[i] = true;
Edge firstEdge = vertexes[i].firstEdge;
while (firstEdge != null) {
if (!visited[firstEdge.vertex]) {
depthFirstSearch(visited, firstEdge.vertex);
}
firstEdge = firstEdge.nextEdge;
}
}
//邻接表中边对应的链表的顶点
private class Edge {
int vertex;//该边所指向顶点的位置
Edge nextEdge;//指向下一条弧的指针
}
//邻接表中表的顶点
private class Vertex {
String data;//顶点信息
Edge firstEdge;//指向第一条依附该顶点的弧
}
private Vertex[] vertexes;//顶点数组
/**
* 根据用户输入构造图
*/
public void createGraph() {
Scanner scanner = new Scanner(System.in);
System.out.println("please input vertex number:");
int vertexNum = scanner.nextInt();
System.out.println("please input edge number:");
int edgeNum = scanner.nextInt();
//无向图有n个顶点,最多有n*(n-1)/2条边
// vertex: n = > edge: (n-1)*n/2
if (vertexNum < 1 || edgeNum < 1 || edgeNum > (vertexNum - 1) * vertexNum / 2) {
System.err.println("input error, invalid vertex or edges!");
return;
}
//init vertex and edges
vertexes = new Vertex[vertexNum];
System.out.println("input the vertex by space:");
for (int i = 0; i < vertexNum; i++) {
vertexes[i] = new Vertex();
vertexes[i].data = scanner.next();
vertexes[i].firstEdge = null;
}
System.out.println("input the edge between vertex by pair:");
for (int i = 0; i < edgeNum; i++) {
String v1 = scanner.next();
String v2 = scanner.next();
int start = getPosition(v1);
int end = getPosition(v2);
if (start == -1 || end == -1) {
System.err.println(v1 + " or " + v2 + " are invalid!");
}
if (vertexes[start].firstEdge == null) {
Edge edge = new Edge();
edge.vertex = end;
edge.nextEdge = null;
vertexes[start].firstEdge = edge;
} else {
Edge firstEdge = vertexes[start].firstEdge;
while (firstEdge.nextEdge != null) {
firstEdge = firstEdge.nextEdge;
}
Edge edge = new Edge();
edge.vertex = end;
edge.nextEdge = null;
firstEdge.nextEdge = edge;
}
//无向图,需要进行双向链接
if (vertexes[end].firstEdge == null) {
Edge edge = new Edge();
edge.vertex = start;
edge.nextEdge = null;
vertexes[end].firstEdge = edge;
} else {
Edge firstEdge = vertexes[end].firstEdge;
while (firstEdge.nextEdge != null) {
firstEdge = firstEdge.nextEdge;
}
Edge edge = new Edge();
edge.vertex = start;
edge.nextEdge = null;
firstEdge.nextEdge = edge;
}
}
System.out.println("打印顶点如下:");
for (int i = 0; i < vertexes.length; i++) {
String data = vertexes[i].data;
System.out.print(data + "\t");
}
System.out.println("\n打印边的邻接表如下:");
for (int i = 0; i < vertexes.length; i++) {
Edge firstEdge = vertexes[i].firstEdge;
System.out.print(vertexes[i].data);
while (firstEdge != null) {
System.out.print("--" + vertexes[firstEdge.vertex].data);
firstEdge = firstEdge.nextEdge;
}
System.out.print("\t");
}
}
private int getPosition(String v1) {
for (int i = 0; i < vertexes.length; i++) {
if (vertexes[i].data.equals(v1)) {
return i;
}
}
return -1;
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/graph/UndirectedGraphByAdjacencyMatrix.java
================================================
package cn.codepub.algorithms.graph;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Queue;
import java.util.Scanner;
/**
* <p>
* Created with IntelliJ IDEA. 2015/12/1 18:21
* </p>
* <p>
* ClassName:UndirectedGraphByAdjacencyMatrix
* </p>
* <p>
* Description:使用邻接矩阵实现无向图的深度优先及广度优先
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class UndirectedGraphByAdjacencyMatrix {
private String[] vertex;//顶点集合
private int[][] edges;//边的集合
public static void main(String[] args) {
UndirectedGraphByAdjacencyMatrix undirectedGraphByAdjacencyMatrix = new UndirectedGraphByAdjacencyMatrix();
undirectedGraphByAdjacencyMatrix.createGraph();//创建图
// test data following
// please input vertex number:
// 7
// please input edge number:
// 7
// input the vertex by space:
// a b c d e f g
// input the edge between vertex by pair:
// a c a d a f b c c d e g f g
undirectedGraphByAdjacencyMatrix.depthFirstSearch();//开始深度优先
undirectedGraphByAdjacencyMatrix.breadthFirstSearch();
}
public void breadthFirstSearch() {
//设置访问标记数组
System.out.println("\nBreadth First Search:");
boolean[] visited = new boolean[vertex.length];
Queue<Integer> queue = new ArrayDeque<>();
for (int i = 0; i < vertex.length; i++) {
if (!visited[i]) {
System.out.print(vertex[i] + "\t");
queue.add(i);
visited[i] = true;
}
while (!queue.isEmpty()) {
int remove = queue.remove();
int count = 0;
for (int j = getNextVertex(remove, count); j >= 0; j = getNextVertex(remove, count)) {
if (!visited[j]) {
visited[j] = true;
System.out.print(vertex[j] + "\t");
queue.add(j);
} else {
count++;
}
}
}
}
}
/**
* 根据用户输入构造图
*/
public void createGraph() {
Scanner scanner = new Scanner(System.in);
System.out.println("please input vertex number:");
int vertexNum = scanner.nextInt();
System.out.println("please input edge number:");
int edgeNum = scanner.nextInt();
//无向图有n个顶点,最多有n*(n-1)/2条边
// vertex: n = > edge: (n-1)*n/2
if (vertexNum < 1 || edgeNum < 1 || edgeNum > (vertexNum - 1) * vertexNum / 2) {
System.err.println("input error, invalid vertex or edges!");
return;
}
//init vertex and edges
vertex = new String[vertexNum];
edges = new int[vertexNum][vertexNum];
System.out.println("input the vertex by space:");
for (int i = 0; i < vertexNum; i++) {
vertex[i] = scanner.next();
}
System.out.println("input the edge between vertex by pair:");
for (int i = 0; i < edgeNum; i++) {
String v1 = scanner.next();
String v2 = scanner.next();
int start = getPosition(v1);
int end = getPosition(v2);
if (start == -1 || end == -1) {
System.err.println(v1 + " or " + v2 + " are invalid!");
}
//更新边的邻接矩阵
edges[start][end] = 1;
edges[end][start] = 1;
}
System.out.println("打印顶点如下:" + Arrays.toString(vertex));
System.out.println("打印边的邻接矩阵如下:");
for (int temp[] : edges) {
System.out.println(Arrays.toString(temp));
}
}
/**
* 对外暴露的调用接口
*/
public void depthFirstSearch() {
//设置访问标记数组
boolean[] visited = new boolean[vertex.length];
System.out.println("Depth First Search:");
for (int i = 0; i < vertex.length; i++) {
if (!visited[i]) {
depthFirstSearch(visited, i);
}
}
}
/**
* 内部递归的深度优先实现
*
* @param visited
* @param i
*/
private void depthFirstSearch(boolean[] visited, int i) {
visited[i] = true;
System.out.print(vertex[i] + "\t");
int count = 0;
for (int j = getNextVertex(i, count); j >= 0; j = getNextVertex(i, count)) {
if (!visited[j]) {
depthFirstSearch(visited, j);
} else {
count++;
}
}
}
/**
* 寻找与当前点有边相连的下一个顶点
*
* @param row 查找该行
* @param col 从该列开始查找
* @return
*/
private int getNextVertex(int row, int col) {
for (int j = col; j < edges[row].length; j++) {
if (edges[row][j] == 1) {
return j;
}
}
return -1;
}
/**
* 返回顶点在集合中的位置
*
* @param s
* @return
*/
public int getPosition(String s) {
for (int i = 0; i < vertex.length; i++) {
if (vertex[i].equalsIgnoreCase(s)) {
return i;
}
}
return -1;
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/graph/utils/UnionFindSet.java
================================================
package cn.codepub.algorithms.graph.utils;
/**
* <p>
* Created with IntelliJ IDEA. 15/12/16 16:34
* </p>
* <p>
* ClassName:UnionFindSet
* </p>
* <p>
* Description:实现一个Java版并查集,应用于克鲁斯卡尔算法
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class UnionFindSet {
public int[] father;//father[i]=i表示本集合且i是集合对应的树的根,father[i]=j表示j是i的父节点
public int[] rank;//rank[i]代表集合的秩,比如子孙个数或者树的高度等。用于合并集合,秩小的合并到秩大的
private int DEFAULT_SIZE = 2 << 9;//设置默认值为1024
public UnionFindSet() {
init();
}
public UnionFindSet(int size) {
DEFAULT_SIZE = size;
init();
}
/**
* 利用默认值做初始化工作
*/
private void init() {
father = new int[DEFAULT_SIZE];
rank = new int[DEFAULT_SIZE];
makeSet();
}
/**
* 初始化集合
*/
public void makeSet() {
for (int i = 0; i < father.length; i++) {
father[i] = i;
rank[i] = 0;
}
}
/**
* 查找一个元素所在的集合,其精髓是找到这个元素所在的集合的祖先,如果需要判断两个元素是否属于同一个集合,只要看他们所在集合的祖先是否相同即可
*
* @param x
* @return
*/
public int findSet(int x) {
if (x != father[x]) {
//在递归查找的时候进行了路径压缩,所谓的路径压缩其实非常简单,就是将该树的祖先置为每个节点的父节点
father[x] = findSet(father[x]);
}
return father[x];
}
/**
* 合并树,将秩小的合并到大的
*
* @param x
* @param y
*/
public void union(int x, int y) {
x = findSet(x);
y = findSet(y);
if (x == y) {
return;
}
if (rank[x] > rank[y]) {
father[y] = x;
} else if (rank[x] < rank[y]) {
father[x] = y;
} else {//任意合并一个即可
rank[y]++;
father[x] = y;
}
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/matrix/Matrix.java
================================================
package cn.codepub.algorithms.matrix;
/**
* <p>
* Created with IntelliJ IDEA. 2015/10/10 20:37
* </p>
* <p>
* ClassName:Matrix
* </p>
* <p>
* Description:方阵的乘法
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class Matrix {
static int[][] a = new int[][]{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
static int[][] b = new int[][]{{1, 2, 3}, {1, 2, 3}, {1, 2, 3}};
static int[][] c = new int[a.length][b.length];
public static void main(String[] args) {
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a[i].length; j++) {
for (int k = 0; k < b[j].length; k++) {
c[i][j] += a[i][k] * b[k][j];
}
}
}
for (int temp[] : c) {
for (int col : temp) {
System.out.print(col + "\t");
}
System.out.println();
}
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/multithread/ThreadSynchronization.java
================================================
package cn.codepub.algorithms.multithread;
import java.util.concurrent.atomic.AtomicInteger;
/**
* <p>
* Created with IntelliJ IDEA. 2015/10/29 21:43
* </p>
* <p>
* ClassName:ThreadSynchronization
* </p>
* <p>
* Description:开启三个线程,这三个线程的ID分别是A,B,C,每个线程将自己的ID在屏幕上打印10遍,要求输出结果必须按ABC的顺序显示,例如ABCABC...
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class ThreadSynchronization extends Thread {
private AtomicInteger synObj;//全局共享的同步计数器
private String name;//每个线程的ID
private int flag;//每个线程的标识,用来判断该第几个线程打印了
private int count = 0;//记录打印次数
public ThreadSynchronization(AtomicInteger synObj, String name, int flag) {
this.synObj = synObj;
this.name = name;
this.flag = flag;
}
@Override
public void run() {
while (true) {
synchronized (synObj) {
if (synObj.get() % 3 == flag) {
synObj.set(synObj.get() + 1);
System.out.print(name);
count++;
synObj.notifyAll();
if (count == 10) {
break;
}
} else {
try {
synObj.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
}
public static void main(String[] args) {
AtomicInteger atomicInteger = new AtomicInteger(0);
ThreadSynchronization tp = new ThreadSynchronization(atomicInteger, "A", 0);
ThreadSynchronization tp1 = new ThreadSynchronization(atomicInteger, "B", 1);
ThreadSynchronization tp2 = new ThreadSynchronization(atomicInteger, "C", 2);
tp.start();
tp1.start();
tp2.start();
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/queue/PriorityApp.java
================================================
package cn.codepub.algorithms.queue;
/**
* <p>
* Created with IntelliJ IDEA. 2016/1/8 19:57
* </p>
* <p>
* ClassName:PriorityApp
* </p>
* <p>
* Description:Implements a simple priority queue
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class PriorityApp {
public static void main(String[] args) {
PriorityQ thePQ = new PriorityApp().new PriorityQ(5);
thePQ.insert(30);
thePQ.insert(50);
thePQ.insert(10);
thePQ.insert(40);
thePQ.insert(20);
while (!thePQ.isEmpty()) {
long item = thePQ.remove();
System.out.print(item + " ");
}
}
class PriorityQ {
private int maxSize;
private long[] queArray;
private int nItems;
public PriorityQ(int s) {
maxSize = s;
queArray = new long[maxSize];
nItems = 0;
}
public void insert(long item) {
int j;
if (nItems == 0) {
queArray[nItems++] = item;
} else {
for (j = nItems - 1; j >= 0; j--) {
if (item > queArray[j]) {
queArray[j + 1] = queArray[j];
} else {
break;
}
}
queArray[j + 1] = item;
nItems++;
}
}
public long remove() {
return queArray[--nItems];
}
public long peekMin() {
return queArray[nItems - 1];
}
public boolean isEmpty() {
return nItems == 0;
}
public boolean isFull() {
return nItems == maxSize;
}
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/similarity/cilin/WordSimilarity.java
================================================
package cn.codepub.algorithms.similarity.cilin;
import com.google.common.base.Preconditions;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import static java.lang.Math.PI;
import static java.lang.Math.cos;
/**
* <p>
* Created with IntelliJ IDEA. 2015/8/2 21:54
* </p>
* <p>
* ClassName:WordSimilarity 同义词词林扩展版计算词语相似度
* </p>
* <p>
* Description:<br/>
* "=" 代表 相等 同义 <br/>
* "#" 代表 不等 同类 属于相关词语 <br/>
* "@" 代表 自我封闭 独立 它在词典中既没有同义词, 也没有相关词 <br/>
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
@Log4j2
//注意使用Log4j2的注解,那么在pom中必须引入2.x版本的log4j,如果使用Log4j注解,pom中引入1.x版本的log4j
//相应的配置文件也要一致,2.x版本配置文件为log4j2.xml,1.x版本配置文件为log4j.xml
public class WordSimilarity {
/**
* when we use Lombok's Annotation, such as @Log4j
*
* @Log4j <br/>
* public class LogExample {
* }
* <p>
* will generate:
* public class LogExample {
* private static final org.apache.logging.log4j.Logger log = org.apache.logging.log4j.Logger.getLogger(LogExample.class);
* }
* </p>
*/
//定义一些常数先
private static final double a = 0.65;
private static final double b = 0.8;
private static final double c = 0.9;
private static final double d = 0.96;
private static final double e = 0.5;
private static final double f = 0.1;
private static final double degrees = 180;
//存放的是以词为key,以该词的编码为values的List集合,其中一个词可能会有多个编码
private static Map<String, ArrayList<String>> wordsEncode = new HashMap<String, ArrayList<String>>();
//存放的是以编码为key,以该编码多对应的词为values的List集合,其中一个编码可能会有多个词
private static Map<String, ArrayList<String>> encodeWords = new HashMap<String, ArrayList<String>>();
/**
* 读取同义词词林并将其注入wordsEncode和encodeWords
*/
private static void readCiLin() {
InputStream input = WordSimilarity.class.getClass().getResourceAsStream("/cilin.txt");
List<String> contents = null;
try {
contents = IOUtils.readLines(input);
for (String content : contents) {
content = Preconditions.checkNotNull(content);
String[] strsArr = content.split(" ");
String[] strs = Preconditions.checkNotNull(strsArr);
String encode = null;
int length = strs.length;
if (length > 1) {
encode = strs[0];//获取编码
}
ArrayList<String> encodeWords_values = new ArrayList<String>();
for (int i = 1; i < length; i++) {
encodeWords_values.add(strs[i]);
}
encodeWords.put(encode, encodeWords_values);//以编码为key,其后所有值为value
for (int i = 1; i < length; i++) {
String key = strs[i];
if (wordsEncode.containsKey(strs[i])) {
ArrayList<String> values = wordsEncode.get(key);
values.add(encode);
//重新放置回去
wordsEncode.put(key, values);//以某个value为key,其可能的所有编码为value
} else {
ArrayList<String> temp = new ArrayList<String>();
temp.add(encode);
wordsEncode.put(key, temp);
}
}
}
} catch (IOException e) {
e.printStackTrace();
System.err.println("load dictionary failed!");
log.error(e.getMessage());
}
}
/**
* 对外暴露的接口,返回两个词的相似度的计算结果
*
* @param word1
* @param word2
* @return 相似度值
*/
public static double getSimilarity(String word1, String word2) {
//在计算时候再加载,实现懒加载
readCiLin();
//如果比较词没有出现在同义词词林中,则相似度为0
if (!wordsEncode.containsKey(word1) || !wordsEncode.containsKey(word2)) {
return 0;
}
//获取第一个词的编码
ArrayList<String> encode1 = getEncode(word1);
//获取第二个词的编码
ArrayList<String> encode2 = getEncode(word2);
double maxValue = 0;//最终的计算结果值,取所有相似度里面结果最大的那个
for (String e1 : encode1) {
for (String e2 : encode2) {
log.info(e1);
log.info(e2);
String commonStr = getCommonStr(e1, e2);
int length = StringUtils.length(commonStr);
double k = getK(e1, e2);
double n = getN(commonStr);
log.info("k-->" + k);
log.info("n-->" + n);
log.info("encode length-->" + length);
double res = 0;
//如果有一个以“@”那么表示自我封闭,肯定不在一棵树上,直接返回f
if (e1.endsWith("@") || e2.endsWith("@") || 0 == length) {
if (f > maxValue) {
maxValue = f;
}
continue;
}
if (1 == length) {
//说明在第二层上计算
res = a * cos(n * PI / degrees) * ((n - k + 1) / n);
} else if (2 == length) {
//说明在第三层上计算
res = b * cos(n * PI / degrees) * ((n - k + 1) / n);
} else if (4 == length) {
//说明在第四层上计算
res = c * cos(n * PI / degrees) * ((n - k + 1) / n);
} else if (5 == length) {
//说明在第五层上计算
res = d * cos(n * PI / degrees) * ((n - k + 1) / n);
} else {
//注意不存在前面七个字符相同,而结尾不同的情况,所以这个分支一定是8个字符都相同,那么只需比较结尾即可
if (e1.endsWith("=") && e2.endsWith("=")) {
//说明两个完全相同
res = 1;
} else if (e1.endsWith("#") && e2.endsWith("#")) {
//只有结尾不同,说明结尾是“#”
res = e;
}
}
log.info("res: " + res);
if (res > maxValue) {
maxValue = res;
}
}
}
return maxValue;
}
/**
* 判断一个词在同义词词林中是否是自我封闭的,是否是独立的
*
* @param source
* @return
*/
private boolean isIndependent(String source) {
Iterator<String> iter = wordsEncode.keySet().iterator();
while (iter.hasNext()) {
String key = iter.next();
if (StringUtils.equalsIgnoreCase(key, source)) {
ArrayList<String> values = wordsEncode.get(key);
for (String value : values) {
if (value.endsWith("@")) {
return true;
}
}
}
}
return false;
}
/**
* 根据word的内容,返回其对应的编码
*
* @param word
* @return
*/
protected static ArrayList<String> getEncode(String word) {
return wordsEncode.get(word);
}
/**
* 计算N的值,N表示所在分支层分支数,如:人 Aa01A01= 和 少儿 Ab04B01=,以A开头的子分支只有14个
* 这一点在论文中说的非常不清晰,所以以国人的文章进行编码真是痛苦
*
* @param encodeHead 输入两个字符串的公共开头
* @return 经过计算之后得到N的值
*/
protected static int getN(String encodeHead) {
int length = StringUtils.length(encodeHead);
switch (length) {
case 1:
return getCount(encodeHead, 2);
case 2:
return getCount(encodeHead, 4);
case 4:
return getCount(encodeHead, 5);
case 5:
return getCount(encodeHead, 7);
default:
return 0;
}
}
protected static int getCount(String encodeHead, int end) {
Set<String> res = new HashSet<String>();
Iterator<String> iter = encodeWords.keySet().iterator();
while (iter.hasNext()) {
String curr = iter.next();
if (curr.startsWith(encodeHead)) {
String temp = curr.substring(0, end);
if (res.contains(temp)) {
continue;
} else {
res.add(temp);
}
}
}
return res.size();
}
/**
* @param encode1 第一个编码
* @param encode2 第二个编码
* @return 这两个编码对应的分支间的距离,用k表示
*/
protected static int getK(String encode1, String encode2) {
String temp1 = encode1.substring(0, 1);
String temp2 = encode2.substring(0, 1);
if (StringUtils.equalsIgnoreCase(temp1, temp2)) {
temp1 = encode1.substring(1, 2);
temp2 = encode2.substring(1, 2);
} else {
return Math.abs(temp1.charAt(0) - temp2.charAt(0));
}
if (StringUtils.equalsIgnoreCase(temp1, temp2)) {
temp1 = encode1.substring(2, 4);
temp2 = encode2.substring(2, 4);
} else {
return Math.abs(temp1.charAt(0) - temp2.charAt(0));
}
if (StringUtils.equalsIgnoreCase(temp1, temp2)) {
temp1 = encode1.substring(4, 5);
temp2 = encode2.substring(4, 5);
} else {
return Math.abs(Integer.valueOf(temp1) - Integer.valueOf(temp2));
}
if (StringUtils.equalsIgnoreCase(temp1, temp2)) {
temp1 = encode1.substring(5, 7);
temp2 = encode2.substring(5, 7);
} else {
return Math.abs(temp1.charAt(0) - temp2.charAt(0));
}
return Math.abs(Integer.valueOf(temp1) - Integer.valueOf(temp2));
}
/**
* 获取编码的公共部分字符串
*
* @param encode1
* @param encode2
* @return
*/
protected static String getCommonStr(String encode1, String encode2) {
int length = StringUtils.length(encode1);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < length; i++) {
if (encode1.charAt(i) == encode2.charAt(i)) {
sb.append(encode1.charAt(i));
} else {
break;
}
}
int sbLen = StringUtils.length(sb);
//注意第三层和第五层均有两个字符,所以长度不可能出现3和6的情况
if (sbLen == 3 || sbLen == 6) {
sb.deleteCharAt(sbLen - 1);
}
return String.valueOf(sb);
}
@Test
public void testGetN() {
readCiLin();
int a = getN("A");
System.out.println(a);
}
@Test
public void testGetK() {
int k = getK("Aa01A01=", "Aa01A01=");
System.out.println(k);
}
@Test
public void testGetCommonStr() {
String commonStr = getCommonStr("Aa01A01=", "Aa01A03=");
System.out.println(commonStr);
}
@Test
public void testGetSimilarity() {
readCiLin();
double similarity = getSimilarity("人民", "国民");
System.out.println("人民--" + "国民:" + similarity);
similarity = getSimilarity("人民", "群众");
System.out.println("人民--" + "群众:" + similarity);
similarity = getSimilarity("人民", "党群");
System.out.println("人民--" + "党群:" + similarity);
similarity = getSimilarity("人民", "良民");
System.out.println("人民--" + "良民:" + similarity);
similarity = getSimilarity("人民", "同志");
System.out.println("人民--" + "同志:" + similarity);
similarity = getSimilarity("人民", "成年人");
System.out.println("人民--" + "成年人:" + similarity);
similarity = getSimilarity("人民", "市民");
System.out.println("人民--" + "市民:" + similarity);
similarity = getSimilarity("人民", "亲属");
System.out.println("人民--" + "亲属:" + similarity);
similarity = getSimilarity("人民", "志愿者");
System.out.println("人民--" + "志愿者:" + similarity);
similarity = getSimilarity("人民", "先锋");
System.out.println("人民--" + "先锋:" + similarity);
}
@Test
public void testGetSimilarity2() {
readCiLin();
double similarity = getSimilarity("非洲人", "亚洲人");
System.out.println(similarity);
double similarity1 = getSimilarity("地震", "电");
System.out.println(similarity1);
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/sorting/BubbleSort.java
================================================
package cn.codepub.algorithms.sorting;
import org.junit.Test;
import java.util.Arrays;
/**
* <p>
* Created with IntelliJ IDEA. 2016/1/8 19:37
* </p>
* <p>
* ClassName:BubbleSort
* </p>
* <p>
* Description:冒泡排序
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class BubbleSort {
public void bubbleSort(int[] nums) {
for (int i = 0; i < nums.length; i++) {
for (int j = nums.length - 1; j > i; j--) {
if (nums[i] > nums[j]) {
swap(nums, i, j);
}
}
}
}
public void swap(int[] nums, int one, int two) {
int temp = nums[one];
nums[one] = nums[two];
nums[two] = temp;
}
@Test
public void test() {
int[] nums = new int[]{7, 3, 4, 23, 3, 9};
bubbleSort(nums);
System.out.println(Arrays.toString(nums));
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/sorting/InsertSort.java
================================================
package cn.codepub.algorithms.sorting;
import java.util.Arrays;
/**
* <p>
* Created with IntelliJ IDEA. 2015/10/17 22:30
* </p>
* <p>
* ClassName:InsertSort
* </p>
* <p>
* Description:插入排序
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class InsertSort {
public static void main(String[] args) {
int[] nums = new int[]{9090, 4, 5, 2, 3, 1, 4, 5, 4, 4, 8989, 4};
for (int i = 1; i < nums.length; i++) {
for (int j = i; j > 0; j--) {
if (nums[j] < nums[j - 1]) {
swap(nums, j, j - 1);
}
}
}
System.out.println(Arrays.toString(nums));
}
//交换函数
private static void swap(int[] nums, int first, int second) {
int temp = nums[first];
nums[first] = nums[second];
nums[second] = temp;
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/sorting/QuickSort.java
================================================
package cn.codepub.algorithms.sorting;
import java.util.Arrays;
/**
* <p>
* Created with IntelliJ IDEA. 2015/10/21 14:42
* </p>
* <p>
* ClassName:QuickSort
* </p>
* <p>
* Description:快速排序
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class QuickSort {
public static void main(String[] args) {
int[] nums = new int[]{3, 4, 5, 9, 1, 2, 33, 11, 22};
new QuickSort().quickSort(nums, 0, nums.length - 1);
System.out.println(Arrays.toString(nums));
}
public void quickSort(int nums[], int start, int end) {
if (start >= end) {
return;
}
int left = start;
int right = end - 1;
int mid = nums[end];
while (left < right) {
while (nums[left] < mid && left < right) {
left++;
}
while (nums[right] > mid && left < right) {
right--;
}
swap(nums, left, right);
}
if (nums[left] > mid) {
swap(nums, left, end);
} else {
left++;
}
quickSort(nums, start, left - 1);
quickSort(nums, left + 1, end);
}
private void swap(int nums[], int left, int right) {
int temp = nums[left];
nums[left] = nums[right];
nums[right] = temp;
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/sorting/SelectionSort.java
================================================
package cn.codepub.algorithms.sorting;
import org.junit.Test;
import java.util.Arrays;
/**
* <p>
* Created with IntelliJ IDEA. 2016/1/8 19:43
* </p>
* <p>
* ClassName:SelectionSort
* </p>
* <p>
* Description:选择排序
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class SelectionSort {
public void selectionSort(int[] nums) {
int min;
for (int i = 0; i < nums.length; i++) {
min = i;
for (int j = i + 1; j < nums.length; j++) {
if (nums[j] < nums[min]) {
min = j;
}
}
swap(nums, i, min);
}
}
public void swap(int[] nums, int one, int two) {
int temp = nums[one];
nums[one] = nums[two];
nums[two] = temp;
}
@Test
public void test() {
int[] nums = new int[]{9, 3, 4, 22, 33, 1, 9, 11, 10};
selectionSort(nums);
System.out.println(Arrays.toString(nums));
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/sorting/ShellSort.java
================================================
package cn.codepub.algorithms.sorting;
import java.util.Arrays;
/**
* <p>
* Created with IntelliJ IDEA. 2015/10/19 10:17
* </p>
* <p>
* ClassName:ShellSort
* </p>
* <p>
* Description:希尔排序
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class ShellSort {
public static void main(String[] args) {
int[] nums = new int[]{9, 8, 7, 6, 4, 1, 11, 12, 122, 122, 1222, 12222, 14433};
int length = nums.length;
int d = 1;
while (d < length / 3) {
//之所以对d进行这种操作,是因为如下性质:使用递增序列1, 4, 13, 40, 121, 364…的希尔排序所需的比较次数不会超出N的若干倍乘以递增序列的长度
d = d * 3 + 1;
}
while (d >= 1) {
for (int i = d; i < length; i++) {
for (int j = i; j >= d; j -= d) {
if (nums[j - d] > nums[j]) {
swap(nums, j, j - d);
}
}
}
d = d / 3;
}
System.out.println(Arrays.toString(nums));
}
private static void swap(int[] nums, int first, int second) {
int temp = nums[first];
nums[first] = nums[second];
nums[second] = temp;
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/spelling/ChineseToSpelling.java
================================================
package cn.codepub.algorithms.spelling;
import com.github.stuxuhai.jpinyin.PinyinFormat;
import com.github.stuxuhai.jpinyin.PinyinHelper;
/**
* <p>
* Created with IntelliJ IDEA. 2015/12/12 23:47
* </p>
* <p>
* ClassName:ChineseToSpelling
* </p>
* <p>
* Description:使用JPinyin组件将汉字转成拼音
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class ChineseToSpelling {
/**
*
*/
public static String convertChineseToSpelling(String chinese, SpellingFormat spellingFormat) {
String res = null;
switch (spellingFormat) {
case WITH_TONE_MARK:
res = PinyinHelper.convertToPinyinString(chinese, ",", PinyinFormat.WITH_TONE_MARK); // nǐ,hǎo,shì,jiè
break;
case WITH_TONE_NUMBER:
res = PinyinHelper.convertToPinyinString(chinese, ",", PinyinFormat.WITH_TONE_NUMBER); // ni3,hao3,shi4,jie4
break;
case WITHOUT_TONE:
res = PinyinHelper.convertToPinyinString(chinese, ",", PinyinFormat.WITHOUT_TONE); // ni,hao,shi,jie
break;
case SHORT_PINYIN:
res = PinyinHelper.getShortPinyin(chinese); // nhsj
break;
default:
res = "ERROR";
}
return res;
}
}
enum SpellingFormat {
WITH_TONE_MARK, WITH_TONE_NUMBER, WITHOUT_TONE, SHORT_PINYIN;
}
================================================
FILE: src/main/java/cn/codepub/algorithms/stack/BracketsApp.java
================================================
package cn.codepub.algorithms.stack;
import cn.codepub.algorithms.utils.StackX;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* <p>
* Created with IntelliJ IDEA. 2016/1/8 20:17
* </p>
* <p>
* ClassName:BracketsApp
* </p>
* <p>
* Description:判断括号是否匹配,For Example:(((())))
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class BracketsApp {
public static void main(String[] args) throws IOException {
String input;
while (true) {
System.out.println("Enter string containing delimiters:");
System.out.flush();
input = getString();
if (input.equals("")) {
break;
}
BracketChecker theChecker = new BracketChecker(input);
theChecker.check();
}
}
public static String getString() throws IOException {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String str = br.readLine();
return str;
}
}
class BracketChecker {
private String input;
public BracketChecker(String in) {
this.input = in;
}
public void check() {
int stackSize = input.length();
StackX<Character> theStack = new StackX(stackSize);
for (int j = 0; j < input.length(); j++) {
char ch = input.charAt(j);
switch (ch) {
case '{':
case '[':
case '(':
theStack.push(ch);
break;
case '}':
case ']':
case ')':
if (!theStack.isEmpty()) {
char chx = theStack.pop();
if ((ch == '}' && chx != '{') || (ch == ']' && chx != '[')
|| (ch == ')' && chx != '(')) {
System.out.println("Error:" + ch + " at " + (j + 1));
}
} else {
System.out.println("Error:" + ch + " at " + (j + 1));
}
default:
break;
}
}
if (!theStack.isEmpty()) {
System.out.println("Error:missing right delimiter");
} else {
System.out.println("It is legitimate!");
}
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/stack/CheckStackSequence.java
================================================
package cn.codepub.algorithms.stack;
import java.util.Stack;
/**
* <p>
* Created with IntelliJ IDEA. 2015/10/29 21:43
* </p>
* <p>
* ClassName:CheckStackSequence
* </p>
* <p>
* Description:
* 题目:输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否为该栈的弹出顺序。
* 例如序列1,2,3,4,5是某栈的压栈序列,序列4,5,3,2,1是该压栈序列对应的一个弹出序列,但是4,3,5,1,2就不可能是其弹出序列
* <p>
* 解题思路:既然是判断栈的弹栈序列是否合法,那么就用一个栈来模拟弹出序列即可,最后栈空说明全部弹出,合法,否则栈非空说明不合法
* ① 如果下一个弹出元素和刚好要入栈元素一致,两者都向后走
* ② 如果下一个弹出元素和栈顶元素一致,那么先弹栈再入栈
* ③ 如果下一个弹出元素和要入栈元素不一致,且和栈顶元素也不一致,那么将要入栈元素压栈
* ④ 最后如果按照弹栈序列能将栈弹空,那么说明序列合法,否则不合法
* <p>
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class CheckStackSequence {
public static void main(String[] args) {
int[] nums1 = new int[]{1, 2, 3, 4, 5};
int[] nums2 = new int[]{4, 5, 3, 2, 1};
boolean check = check(nums1, nums2);
System.out.println(check);
int[] nums3 = new int[]{1, 4, 5, 2, 3};
boolean check1 = check(nums1, nums3);
System.out.println(check1);
int[] nums4 = new int[]{4, 3, 5, 1, 2};
boolean check2 = check(nums1, nums4);
System.out.println(check2);
int[] nums5 = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9};
int[] nums6 = new int[]{3, 8, 7, 9, 6, 5, 4, 2, 1};
boolean check3 = check(nums5, nums6);
System.out.println(check3);
}
/**
* @param nums1 入栈序列
* @param nums2 出栈序列
* @return 出栈序列是否合法
*/
public static boolean check(int[] nums1, int[] nums2) {
Stack<Integer> stack = new Stack();
int current = 0;
for (int i = 0; i < nums1.length; i++) {
if (nums2[current] == nums1[i]) {//说明该元素入栈之后即刻出栈,所以将i和current递增即刻
current++;
} else {
//如果在下一个元素入栈之前有元素要弹栈,那么需要先弹栈再入栈
if (!stack.isEmpty() && nums2[current] == stack.peek()) {
current++;
stack.pop();
stack.push(nums1[i]);//别忘记将新的元素入栈
} else {
//直接入栈
stack.push(nums1[i]);
}
}
}
//剩下的栈内元素都是依次出栈即可
while (current < nums2.length && nums2[current] == stack.peek() && !stack.isEmpty()) {
current++;
stack.pop();
}
if (stack.isEmpty()) {
return true;
}
return false;
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/stack/InfixApp.java
================================================
package cn.codepub.algorithms.stack;
import cn.codepub.algorithms.utils.StackX;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* <p>
* Created with IntelliJ IDEA. 2016/1/8 19:16
* </p>
* <p>
* ClassName:InfixApp
* </p>
* <p>
* Description:中缀表达式转后缀表达式,For Example<br/>
* Enter infix:<br/>
* 2+4-4+3*2<br/>
* Postfix is 24+4-32*+<br/>
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class InfixApp {
public static void main(String[] args) throws IOException {
String input, output;
while (true) {
System.out.println("Enter infix:");
System.out.flush();
input = getString();
if (input.equals("")) {
break;
}
InToPost theTrans = new InToPost(input);
output = theTrans.doTrans();
System.out.println("Postfix is " + output + "\n");
}
}
public static String getString() throws IOException {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String s = br.readLine();
return s;
}
}
class InToPost {
private StackX<Character> theStack;
private String input;
private String output = "";
public InToPost(String in) {
input = in;
int stackSize = input.length();
theStack = new StackX<Character>(stackSize);
}
public String doTrans() {
for (int j = 0; j < input.length(); j++) {
char ch = input.charAt(j);
theStack.displayStack("For " + ch + " ");
switch (ch) {
case '+':
case '-':
gotOper(ch, 1);
break;
case '*':
case '/':
gotOper(ch, 2);
break;
case '(':
theStack.push(ch);
break;
case ')':
gotParen(ch);
break;
default:
output = output + ch;
break;
}
}
while (!theStack.isEmpty()) {
theStack.displayStack("While ");
output = output + theStack.pop();
}
theStack.displayStack("End ");
return output;
}
public void gotOper(char opThis, int prec1) {
while (!theStack.isEmpty()) {
char opTop = theStack.pop();
if (opTop == '(') {
theStack.push(opTop);
break;
} else {
int prec2;
if (opTop == '+' || opTop == '-') {
prec2 = 1;
} else {
prec2 = 2;
}
if (prec2 < prec1) {
theStack.push(opTop);
break;
} else {
output = output + opTop;
}
}
}
theStack.push(opThis);
}
public void gotParen(char ch) {
while (!theStack.isEmpty()) {
char chx = theStack.pop();
if (chx == '(') {
break;
} else {
output = output + chx;
}
}
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/stack/MinStack.java
================================================
package cn.codepub.algorithms.stack;
import java.util.Stack;
/**
* <p>
* Created with IntelliJ IDEA. 2015/10/29 12:22
* </p>
* <p>
* ClassName:MinStack
* </p>
* <p>
* Description:
* 题目:定义栈的数据结构,请在该类型中实现一个能够得到栈的最小元素的min函数。在该栈中,调用min、push及pop的时间复杂度都是O(1)
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class MinStack {
public static void main(String[] args) {
Stack<Integer> numberStack = new Stack<>();//存储元素的栈
Stack<Integer> minStack = new Stack<>();//到当前元素为止,栈顶始终是最小的一个元素
int nums[] = new int[]{3, 4, 2, 1, 9};
for (int i : nums) {
numberStack.push(i);
if (!minStack.isEmpty() && i > minStack.peek()) {//与minStack的栈顶元素比较,如果比其大,将栈顶元素再次入栈
minStack.push(minStack.peek());
} else {//如果比其小,说明当前最小的元素是i,将i入栈
minStack.push(i);
}
}
System.out.println(numberStack);
System.out.println(minStack);
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/stack/PostfixApp.java
================================================
package cn.codepub.algorithms.stack;
import cn.codepub.algorithms.utils.StackX;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/**
* <p>
* Created with IntelliJ IDEA. 2016/1/8 19:04
* </p>
* <p>
* ClassName:PostfixApp
* </p>
* <p>
* Description:求解后缀表达式,For Example<br/>
* Enter postfix:34*2/<br/>
* 3 Stack(bottom->top):<br/>
* 4 Stack(bottom->top):3<br/>
* Stack(bottom->top):3 4<br/>
* 2 Stack(bottom->top):12<br/>
* / Stack(bottom->top):12 2<br/>
* Evaluates to 6<br/>
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class PostfixApp {
public static void main(String[] args) throws Exception {
String input;
int output;
while (true) {
System.out.print("Enter postfix:");
System.out.flush();
input = getString();
if (input.equals("")) {
break;
}
ParsePost aParse = new ParsePost(input);
output = aParse.doParse();
System.out.println("Evaluates to " + output);
}
}
public static String getString() throws Exception {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader buf = new BufferedReader(isr);
String s = buf.readLine();
return s;
}
}
class ParsePost {
private StackX<Integer> theStack;
private String input;
public ParsePost(String s) {
input = s;
}
public int doParse() {
theStack = new StackX<Integer>(20);
char ch;
int j;
int num1, num2, interAns;
for (j = 0; j < input.length(); j++) {
ch = input.charAt(j);
theStack.displayStack("" + ch + " ");
if (ch >= '0' && ch <= '9') {
theStack.push((int) (ch - '0'));
} else {
num2 = theStack.pop();
num1 = theStack.pop();
switch (ch) {
case '+':
interAns = num1 + num2;
break;
case '-':
interAns = num1 - num2;
break;
case '*':
interAns = num1 * num2;
break;
case '/':
interAns = num1 / num2;
break;
default:
interAns = 0;
break;
}
theStack.push(interAns);
}
}
interAns = theStack.pop();
return interAns;
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/strings/BinarySearch.java
================================================
package cn.codepub.algorithms.strings;
/**
* <p>
* Created with IntelliJ IDEA. 2015/10/15 17:15
* </p>
* <p>
* ClassName:BinarySearch
* </p>
* <p>
* Description:二分查找
* 注意点:数组在传递进来之前一定是排好序的数组,采用递归实现的方法一定要提供出口
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class BinarySearch {
/**
* 递归方式实现二分查找
*
* @param nums 查找的数组
* @param start 开始下标
* @param end 结束下标
* @param key 查找元素
* @return 查找元素的下标,当未查到的时候,返回-1
*/
private static int recursionBinarySearch(int[] nums, int start, int end, int key) {
if (start > end) {
return -1;
}
int mid = start + ((end - start) >> 1);
if (nums[mid] == key) {
return mid;
} else if (nums[mid] > key) {
//说明key在当前分组的左半边
return recursionBinarySearch(nums, start, mid - 1, key);
} else {
//在右半边
return recursionBinarySearch(nums, mid + 1, end, key);
}
}
/**
* 非递归方式实现二分查找
*
* @param nums 查找的数组
* @param key 查找元素
* @return 查找元素的下标,当未查到返回-1
*/
private static int nonRecursionBinarySearch(int[] nums, int key) {
int start = 0;
int end = nums.length - 1;
while (start <= end) {
//防止(start + end) >>1 溢出
//JDK中的Arrays.binarySearch使用(low + high) >>> 1;
int mid = start + ((end - start) >> 1);
if (nums[mid] == key) {
return mid;
} else if (nums[mid] > key) {
end = mid - 1;
} else {
start = mid + 1;
}
}
return -1;
}
public static void main(String[] args) {
int[] nums = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 11};
int i = recursionBinarySearch(nums, 0, nums.length - 1, 11);
System.out.println(i);
i = recursionBinarySearch(nums, 0, nums.length - 1, 12);
System.out.println(i);
i = recursionBinarySearch(nums, 0, nums.length - 1, 0);
System.out.println(i);
i = nonRecursionBinarySearch(nums, 11);
System.out.println(i);
i = nonRecursionBinarySearch(nums, 12);
System.out.println(i);
i = nonRecursionBinarySearch(nums, 0);
System.out.println(i);
nums = new int[]{1};
i = recursionBinarySearch(nums, 0, nums.length - 1, 1);
System.out.println(i);
i = nonRecursionBinarySearch(nums, 1);
System.out.println(i);
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/strings/Combination.java
================================================
package cn.codepub.algorithms.strings;
/**
* <p>
* Created with IntelliJ IDEA. 2015/10/30 21:43
* </p>
* <p>
* ClassName:Combination
* </p>
* <p>
* Description:组合:一般地,从m个不同的元素中,任取n(n≤m)个元素为一组,叫作从m个不同元素中取出n个元素的一个组合
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class Combination {
static StringBuilder sb = new StringBuilder();
public static void main(String[] args) {
char[] strs = new char[]{'a', 'b', 'c', 'd', 'e'};
for (int i = 1; i <= strs.length; i++) {
combination(strs, 0, i);
}
System.out.println("测试第二种方法");
combination();
}
/**
* 第一种方法
*
* @param strs 需要操作的字符数组
* @param start 从哪里开始取
* @param number 取几个字符
*/
public static void combination(char[] strs, int start, int number) {
//定义函数出口先
if (number <= 0 || start >= strs.length) {
System.out.println(sb.toString());
return;
}
//选取当前字符的话,需要将number-1
sb.append(strs[start]);
combination(strs, start + 1, number - 1);
//不选取当前字符的话,number不变
sb.deleteCharAt(sb.length() - 1);
//注意因为还需要从start+1的位置开始取number个字符,那么如果剩下的字符不足number就没必要去取了
if (strs.length - start > number) {
combination(strs, start + 1, number);
}
}
/**
* 第二种方法
* 基本思路:求全组合,则假设原有元素n个,则最终组合结果是2^n个。原因是: 用位操作方法:假设元素原本有:a,b,c三个,则1表示取该元素,0表示不取。故去a则是001,取ab则是011<br/>
* 所以一共三位,每个位上有两个选择0,1。所以是2^n个结果。这些结果的位图值都是0,1,2....2^n。所以可以类似全真表一样,从值0到值2^n依次输出结果:即:000,001,010,011,100,101,110,111<br/>
* 对应输出组合结果为:空,a,b,ab,c,ac,bc,abc. 这个输出顺序刚好跟数字0~2^n结果递增顺序一样 取法的二进制数其实就是从0到2^n-1的十进制数
*/
public static void combination() {
String[] str = {"a", "b", "c"};
int n = str.length; // 元素个数。
// 求出位图全组合的结果个数:2^n
int nbit = 1 << n; // “<<” 表示 左移:各二进位全部左移若干位,高位丢弃,低位补0。:即求出2^n=2Bit。
// System.out.println("全组合结果个数为:" + nbit + ",二进制:" + Integer.toBinaryString(nbit));
for (int i = 0; i < nbit; i++) { // 结果有nbit个。输出结果从数字小到大输出:即输出0,1,2,3,....2^n。
// System.out.print("组合数值 " + i + " 对应编码为: ");
for (int j = 0; j < n; j++) { // 每个数二进制最多可以左移n次,即遍历完所有可能的变化新二进制数值了
int tmp = 1 << j;
// System.out.println("->" + Integer.toBinaryString(tmp));
if ((tmp & i) != 0) { // & 表示与。两个位都为1时,结果才为1
System.out.print(str[j]);
}
}
System.out.println();
}
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/strings/JaccardSimilarityCoefficient.java
================================================
package cn.codepub.algorithms.strings;
import com.google.common.base.Preconditions;
import com.google.common.collect.Sets;
import org.apache.commons.lang3.StringUtils;
import java.util.HashSet;
import java.util.Set;
/**
* <p>
* Created with IntelliJ IDEA. 2015/8/9 14:22
* </p>
* <p>
* ClassName:JaccardSimilarityCoefficient
* </p>
* <p>
* Description:杰卡德相似系数,是衡量两个集合的相似度的一种指标,J(A,B)=|A∩B|/|A∪B|
* 杰卡德距离,是衡量两个集合中不同元素占所有元素的比例来衡量两个集合的区分度,Ja(A,B)=1-J(A,B)
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class JaccardSimilarityCoefficient {
public double getJSC(String str1, String str2) {
if (StringUtils.isEmpty(str1) && StringUtils.isEmpty(str2)) {
return 1;
}
Set<Character> s1 = new HashSet<Character>();
Set<Character> s2 = new HashSet<Character>();
str1 = Preconditions.checkNotNull(str1);
str2 = Preconditions.checkNotNull(str2);
char[] chars1 = str1.toCharArray();
char[] chars2 = str2.toCharArray();
for (char c : chars1) {
s1.add(c);
}
for (char c : chars2) {
s2.add(c);
}
//求交集
Set<Character> intersection = new HashSet<Character>();
intersection.addAll(s1);
intersection.retainAll(s2);
//求并集
Set<Character> union = new HashSet<Character>();
union.addAll(s1);
union.addAll(s2);
return (double) intersection.size() / union.size();
}
public static double calcBySets(String s0, String s1) {
if (s0.isEmpty() && s1.isEmpty()) {
return 1.0;
}
Set<Character> words0 = new HashSet<Character>();
Set<Character> words1 = new HashSet<Character>();
for (int i = 0; i < s0.length(); i++) {
words0.add(s0.charAt(i));
}
for (int i = 0; i < s1.length(); i++) {
words1.add(s1.charAt(i));
}
double intersect = Sets.intersection(words0, words1).size();
double union = Sets.union(words0, words1).size();
System.out.println(Sets.union(words0, words1));
return intersect / union;
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/strings/LCS.java
================================================
package cn.codepub.algorithms.strings;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
/**
* <p>
* Created with IntelliJ IDEA.
* </p>
* <p>
* ClassName:LCS
* </p>
* <p>
* Description:最长公共子序列
* </P>
*
* @author Wang Xu
* @version V1.0.0
*/
public class LCS {
public static String lcsBase(String inputX, String inputY) {
if (StringUtils.isEmpty(inputX) || StringUtils.isEmpty(inputY) || inputX.length() == 0 || inputY.length() == 0) {
return "";
} else {
char x = inputX.charAt(0);
char y = inputY.charAt(0);
if (x == y) {
return lcsBase(inputX.substring(1), inputY.substring(1)) + x;
} else {
return getMax(lcsBase(inputX.substring(1), inputY), lcsBase(inputX, inputY.substring(1)));
}
}
}
private static String getMax(String x, String y) {
Integer xLen = 0;
Integer yLen = 0;
if (StringUtils.isEmpty(x)) {
xLen = 0;
} else {
xLen = x.length();
}
if (StringUtils.isEmpty(y)) {
yLen = 0;
} else {
yLen = y.length();
}
if (xLen >= yLen) {
return x;
} else {
return y;
}
}
@Test
public void test() {
// 蓬安县房屋瓦片被震
String base1 = "落广西陕西震感强烈";
String base2 = "汶川地震致重庆4名学生死亡100多人受伤";
String s = lcsBase(base1, base2);
System.out.println(StringUtils.reverse(s));
String s2 = lcsBase("1233433236676", "98723765655423");
System.out.println(StringUtils.reverse(s2));
String s1 = lcsBase("123s212346我的大中国啊33z", "33z的大中国");
System.out.println(StringUtils.reverse(s1));
Integer a = 10000, b = 1000;
Integer c = 100, d = 100;
System.out.println(a == b);
System.out.println(c == d);
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/strings/LCS2.java
================================================
package cn.codepub.algorithms.strings;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
/**
* <p>
* Created with IntelliJ IDEA.
* </p>
* <p>
* ClassName:LCS2
* </p>
* <p>
* Description:最长公共子串算法
* </P>
*
* @author Wang Xu
* @version V1.0.0
*/
public class LCS2 {
private static Integer getComLen(String firstStr, String secondStr) {
Integer comLen = 0;
while (StringUtils.isNotEmpty(firstStr) && StringUtils.isNotEmpty(secondStr)) {
if (firstStr.charAt(0) == secondStr.charAt(0)) {
comLen += 1;
firstStr = firstStr.substring(1);
secondStr = secondStr.substring(1);
} else {
break;
}
}
return comLen;
}
private static String lcsBase(String inputX, String inputY) {
Integer maxComLen = 0;
Integer commonIndex = 0;
for (int i = 0; i < inputX.length(); i++) {
for (int j = 0; j < inputY.length(); j++) {
Integer comLen = getComLen(inputX.substring(i), inputY.substring(j));
if (comLen > maxComLen) {
maxComLen = comLen;
commonIndex = i;
}
}
}
return inputX.substring(commonIndex, commonIndex + maxComLen);
}
@Test
public void test() {
String s1 = "abcy交罚款撒了德萨 e";
String s2 = "abcx交罚款dfdsafdsa范德萨 e";
String s = lcsBase(s1, s2);
System.out.println(s);
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/strings/LCS3.java
================================================
package cn.codepub.algorithms.strings;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
/**
* <p>
* Created with IntelliJ IDEA.
* </p>
* <p>
* ClassName:LCS3
* </p>
* <p>
* Description:使用动态规划解决最长公共子串
* </P>
*
* @author Wang Xu
* @version V1.0.0
*/
public class LCS3 {
public static String lcsDp(String inputX, String inputY) {
int xLen = 0;
int yLen = 0;
int maxLen = 0, maxIndex = 0;
if (StringUtils.isEmpty(inputX)) {
xLen = 0;
} else {
xLen = inputX.length();
}
if (StringUtils.isEmpty(inputY)) {
yLen = 0;
} else {
yLen = inputY.length();
}
int dp[][] = new int[xLen][yLen];
for (int i = 0; i < xLen; i++) {
for (int j = 0; j < yLen; j++) {
if (inputX.charAt(i) == inputY.charAt(j)) {
if (i != 0 && j != 0) {
dp[i][j] = dp[i - 1][j - 1] + 1;
}
if (0 == i || 0 == j) {
dp[i][j] = 1;
}
if (dp[i][j] > maxLen) {
maxLen = dp[i][j];
maxIndex = i + 1 - maxLen;
}
}
}
}
return inputX.substring(maxIndex, maxIndex + maxLen);
}
@Test
public void test() {
String s1 = "我是美abc国中defg国中间人";
String s2 = "我是abdde我是美中国中国中国人";
String s = lcsDp(s1, s2);
System.out.println(s);
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/strings/LevenshteinDistance.java
================================================
package cn.codepub.algorithms.strings;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
/**
* <p>
* Created with IntelliJ IDEA.
* </p>
* <p>
* ClassName:LevenshteinDistance
* </p>
* <p>
* Description:编辑距离算法
* </P>
*
* @author Wang Xu
* @version V1.0.0
*/
public class LevenshteinDistance {
public static int leDistance(String inputX, String inputY) {
int xLen = StringUtils.length(inputX) + 1;
int yLen = StringUtils.length(inputY) + 1;
int[][] dp = new int[xLen][yLen];
for (int i = 0; i < xLen; i++) {
dp[i][0] = i;
}
for (int j = 0; j < yLen; j++) {
dp[0][j] = j;
}
for (int i = 1; i < xLen; i++) {
for (int j = 1; j < yLen; j++) {
if (inputX.charAt(i - 1) == inputY.charAt(j - 1)) {
dp[i][j] = dp[i - 1][j - 1];
} else {
dp[i][j] = 1 + Math.min(Math.min(dp[i - 1][j], dp[i][j - 1]), dp[i - 1][j - 1]);
}
}
}
return dp[xLen - 1][yLen - 1];
}
@Test
public void test() {
int leDistance = LevenshteinDistance.leDistance("", "aa");
System.out.println(leDistance);
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/strings/LongestDecreasingSubSequence.java
================================================
package cn.codepub.algorithms.strings;
import java.util.ArrayList;
import java.util.List;
/**
* 求解思路(以递减子序列为例):
* 1.用dp[i]代表以当前第i个字符为结尾时,所持有的最长递减子序列的长度
* 2.初始化所有的dp[i]值为1,之后再一步步更新之
* 3.如果nums[i-1]比nums[i]大,那么dp[i]=dp[i-1]+1
* 4.否则的话,要取0<=j<=i之间最大那个dp[j],且该dp[j]满足nums[j]>nums[i],这种情况说明中间跳过了几个元素
* 5.对于满足条件的dp[j]将dp[j]+1赋值给dp[i]
*/
public class LongestDecreasingSubSequence {
public static void main(String[] args) {
int[] nums = new int[]{1, 2, 3, 19, 12, 5, 4, 2, 3, 7, 9, 10, 6, 8, 3, 4, 3, 2, 1};
LongestDecreasingSubSequence longestSubSequence = new LongestDecreasingSubSequence();
List<Integer> longestDecreaseSubSequence = longestSubSequence.getLongestDecreaseSubSequence(nums);
System.out.println(longestDecreaseSubSequence);
List<Integer> longestIncreaseSubSequence = longestSubSequence.getLongestIncreaseSubSequence(nums);
System.out.println(longestIncreaseSubSequence);
}
/**
* @param nums 数组
* @return 最长递减子序列链表
*/
public List<Integer> getLongestDecreaseSubSequence(int[] nums) {
int[] dp = new int[nums.length];
int[] priors = new int[nums.length];//用于记录当前以该元素为最小元素的递减序列中该元素的前驱节点,用于打印序列
for (int i = 0; i < dp.length; i++) {
dp[i] = 1;
}
List<Integer> result = new ArrayList<>();//存储递减子序列
int max = 0;//存储子序列的长度
int endIndex = 0;//存储子序列的最后一个元素的下标
for (int i = 1; i < nums.length; i++) {
if (nums[i - 1] > nums[i]) {//说明连续
dp[i] = dp[i - 1] + 1;
priors[i] = i - 1;
} else {//不连续的话要从第一个开始比较,取最长的一个
for (int j = 0; j < i; j++) {
if (nums[j] > nums[i] && (dp[j] + 1) > dp[i]) {
dp[i] = dp[j] + 1;
priors[i] = j;
}
}
}
if (dp[i] > max) {
max = dp[i];
endIndex = i;
}
}
//将子序列取出加入链表,作为结果返回
while (max > 0) {
result.add(0, nums[endIndex]);
endIndex = priors[endIndex];//priors数组中依次存储的是以当前元素作为子序列的前一个节点的下标
max--;
}
return result;
}
/**
* @param nums 数组
* @return 最长递增子序列链表
*/
public List<Integer> getLongestIncreaseSubSequence(int[] nums) {
int[] dp = new int[nums.length];
int[] priors = new int[nums.length];
for (int i = 0; i < dp.length; i++) {
dp[i] = 1;
}
List<Integer> result = new ArrayList<>();//存储递减子序列
int max = 0;
int endIndex = 0;
for (int i = 1; i < nums.length; i++) {
if (nums[i - 1] < nums[i]) {//说明连续
dp[i] = dp[i - 1] + 1;
priors[i] = i - 1;
} else {//不连续的话要从第一个开始比较,取最长的一个
for (int j = 0; j < i; j++) {
if (nums[j] < nums[i] && (dp[j] + 1) > dp[i]) {
dp[i] = dp[j] + 1;
priors[i] = j;
}
}
}
if (dp[i] > max) {
max = dp[i];
endIndex = i;
}
}
//将子序列取出加入链表,作为结果返回
while (max > 0) {
result.add(0, nums[endIndex]);
endIndex = priors[endIndex];//priors数组中依次存储的是以当前元素作为子序列的前一个节点的下标
max--;
}
return result;
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/strings/Manacher.java
================================================
package cn.codepub.algorithms.strings;
import org.apache.commons.lang3.StringUtils;
import java.util.Arrays;
/**
* <p>
* Created by wangxu on 2016/12/23 10:46.
* </p>
* <p>
* Description: 最长回文子串Manacher算法
* ① 在每个字符之间插入一个特殊字符(如ab插入后#a#b#),将所有的奇数和偶数字符串统一成奇数字符串处理
* ② 用一个辅助数组P,P[id]记录的是以字符str[id]为中心的最长回文串半径
* ③ 那么得到直径为P[id]*2-1(因为原点只有一个),这里面特殊字符始终比真实的字符串多一个,所以再减去一个特出字符P[id]*2-1-1
* ④ 剩下的特殊字符和真实字符各占一半(P[id]*2-1-1)/2=P[id]-1,代表真正的以id为中心的最长回文串
* ⑤ 那么max(P[id])-1就是该字符串的最长回文子串,剩下的就是求P[id]数组了
* </p>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0 <br></br>
* WebSite: http://codepub.cn <br></br>
* Licence: Apache v2 License
*/
public class Manacher {
public static void main(String[] args) {
String str = "tattarrattat";
str = "SatireVeritas";
Manacher manacher = new Manacher();
int maxPalindrome = manacher.getMaxPalindrome(str.toLowerCase());
System.out.println(maxPalindrome);
str = "abababbaba";
maxPalindrome= manacher.getMaxPalindrome(str.toLowerCase());
System.out.println(maxPalindrome);
}
private int getMaxPalindrome(String str) {
int P[];//记录以字符S[i]为中心的最长回文子串向左/向右扩张的半径,包含其自身
int id = 0;//已知右边界的最长回文子串的中心坐标
int maxR = 0;//已知的最长回文子串的右边界坐标
String join = "#" + StringUtils.join(str.toCharArray(), '#') + "#";
char[] chars = join.toCharArray();
P = new int[join.length()];
for (int i = 1; i < P.length; i++) {
int j = id - (i - id);//j是i相对于id的对称点,那么i<maxR的时候,它们必然在对称范围之内,所以P[i]=P[j]
if (maxR > i) {
if (maxR - i > P[j]) {
P[i] = P[j];
} else {
P[i] = maxR - i;//这时最多只能确保i能延展到maxR,对于超过maxR的部分不能确保是否回文,所以其延展半径为(maxR-i)
}
} else {
//仅包含其自身
P[i] = 1;
}
//尝试扩展
while ((i - P[i] >= 0) && (i + P[i] < P.length) && chars[i + P[i]] == chars[i - P[i]]) {
//如果又发现一对回文,延展半径加1
P[i]++;
}
//更新maxR和id
if (i + P[i] > maxR) {
//超过了子串的最右边界
maxR = i + P[i];
id = i;
}
}
Arrays.sort(P);//升序排列
return P[P.length - 1] - 1;
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/strings/PatternStringMatch.java
================================================
package cn.codepub.algorithms.strings;
/**
* <p>
* Created with IntelliJ IDEA. 2015/10/22 15:17
* </p>
* <p>
* ClassName:test
* </p>
* <p>
* Description:模式串查找,当模式串出现在文本中的时候,返回匹配的开始索引值,否则未查到返回-1
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class PatternStringMatch {
public static void main(String[] args) {
PatternStringMatch patternStringMatch = new PatternStringMatch();
int search = patternStringMatch.search("abcdefghi", "ih");
System.out.println(search);
int search2 = patternStringMatch.search("abddfdjskfjd", "jd");
System.out.println(search2);
}
/**
* @param text
* @param pat
* @return 约定:查到了返回匹配的索引值,否则未查到则返回-1
*/
private static int search(String text, String pat) {
int patLen = pat.length();
int textLen = text.length();
int step = textLen - patLen;
if (step < 0) {
return -1;//模式串比文本串长,肯定不存在匹配情况
}
for (int i = 0; i <= step; i++) {
int j;
for (j = 0; j < patLen; j++) {
if (pat.charAt(j) != text.charAt(i + j)) {
break;
}
}
if (j == patLen) {//模式串已经走到结尾了,那么i在文本串中正好是匹配到的模式串的开始索引
return i;
}
}
return -1;
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/strings/Permutation.java
================================================
package cn.codepub.algorithms.strings;
/**
* <p>
* Created with IntelliJ IDEA. 2015/10/30 19:37
* </p>
* <p>
* ClassName:Permutation
* </p>
* <p>
* Description:全排列
* 第一步,排列的精髓是交换和顺序处理,比如,考虑[1,2,3,4]排列,实际上是,1和1,2,3,4分别交换得来
* 1和1交换:[1],[2,3,4]
* 1和2交换:[2],[1,3,4]
* 1和3交换:[3],[2,1,4]
* 1和4交换:[4],[2,3,1]
* <p>
* 那么下面分别考虑上面的四个结果,比如,考虑
* [1],[2,3,4]
* <p>
* 第二步,我们把[1]固定不变,考虑[2,3,4],把它看成是2和2,3,4分别交换,得到如下结果:
* [1]固定,2和2交换:[1],[2],[3,4]
* [1]固定,2和3交换:[1],[3],[2,4]
* [1]固定,2和4交换:[1],[4],[3,2]
* <p>
* 这个时候,再分别考虑第二步之后的三个结果,比如,考虑
* [1],[2],[3,4]
* <p>
* 第三步,我们把[1],[2]固定不变,考虑[3,4],把它看成是3和3,4分别交换,得到如下结果:
* [1][2]固定,3和3交换:[1],[2],[3],[4]
* [1][2]固定,3和4交换:[1],[2],[4],[3]
* <p>
* 从上面分析可以看出,其实第二步就是对第一步的部分递归,同样,第三步也是对第二步的部分递归,当最右边只有一个数字的时候,我们就进行输出
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class Permutation {
static StringBuilder sb = new StringBuilder();
public static void main(String[] args) {
char[] strs = new char[]{'a', 'b', 'c'};
permutation(strs, 0, strs.length);
}
public static void permutation(char[] strs, int start, int end) {
if (start >= end) {
System.out.println(sb.toString());
return;
}
for (int i = start; i < end; i++) {
swap(strs, start, i);
sb.append(strs[start]);
permutation(strs, start + 1, end);
swap(strs, start, i);
sb.deleteCharAt(start);
}
}
private static void swap(char[] chars, int first, int second) {
char temp = chars[first];
chars[first] = chars[second];
chars[second] = temp;
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/strings/ReverseString.java
================================================
package cn.codepub.algorithms.strings;
import cn.codepub.algorithms.utils.StackX;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/**
* <p>
* Created with IntelliJ IDEA. 2016/1/8 19:32
* </p>
* <p>
* ClassName:ReverseString
* </p>
* <p>
* Description:反转字符串,例如abc->cba
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class ReverseString {
private String input;
private String output = "";//默认是null,所以此处将""赋值给它
public ReverseString(String in) {
input = in;
}
public String doRev() {
int stackSize = input.length();
StackX<Character> theStack = new StackX(stackSize);
for (int j = 0; j < input.length(); j++) {
char ch = input.charAt(j);
theStack.push(ch);
}
while (!theStack.isEmpty()) {
char ch = theStack.pop();
output = output + ch;
}
return output;
}
public static String getString() throws Exception {
InputStreamReader isr = new InputStreamReader(System.in, "UTF-8");
BufferedReader br = new BufferedReader(isr);
String s = br.readLine();
return s;
}
public static void main(String[] args) throws Exception {
String input, output;
while (true) {
System.out.println("Enter a String:");
System.out.flush();
input = ReverseString.getString();
if (input.equals("")) {
break;
}
ReverseString reverse = new ReverseString(input);
output = reverse.doRev();
System.out.println("Reversed:" + output);
}
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/strings/StringSort.java
================================================
package cn.codepub.algorithms.strings;
import java.util.Arrays;
/**
* <p>
* Created with IntelliJ IDEA. 2015/12/1 14:18
* </p>
* <p>
* ClassName:StringSort
* </p>
* <p>
* Description:实现一个简单的字符串按照字典序排序,不区分大小写
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class StringSort {
public static void main(String[] args) {
String[] strs = new String[]{"alphabet", "alligator", "alternate", "alternative"};
bubbleSort(strs);
System.out.println(Arrays.toString(strs));
}
/**
* 实现排序函数的主体
*
* @param strs 需要排序的字符串数组
*/
public static void bubbleSort(String[] strs) {
for (int i = 0; i < strs.length; i++) {
for (int j = strs.length - 1; j > i; j--) {
int compare = compare(strs[i], strs[j]);
if (compare > 0) {
//说明前面一个大
String temp = strs[i];
strs[i] = strs[j];
strs[j] = temp;
}
}
}
}
/**
* 辅助排序函数
*
* @param s1
* @param s2
* @return 1 前者大;-1 后者大;0 两者相等
*/
private static int compare(String s1, String s2) {
s1 = s1.toLowerCase();//全转小写
s2 = s2.toLowerCase();
int len1 = s1.length();
int len2 = s2.length();
int count = len1 < len2 ? len1 : len2;
for (int i = 0; i < count; i++) {
int first = (int) s1.charAt(i);//将字母强转为ASCII码
int second = (int) s2.charAt(i);
if (first < second) {
return -1;//前一个小
} else if (first > second) {
return 1;//后一个小
} else {
continue;
}
}
//如果全部比较完了,则谁短谁小
if (len1 < len2) {
return -1;
} else if (len1 > len2) {
return 1;
} else {
return 0;
}
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/trees/DepthFirstTraversal.java
================================================
package cn.codepub.algorithms.trees;
import cn.codepub.algorithms.utils.Tree;
import java.util.Stack;
/**
* <p>
* Created with IntelliJ IDEA. 2015/10/30 17:32
* </p>
* <p>
* ClassName:DepthFirstTraversal
* </p>
* <p>
* Description:二叉树的深度优先遍历
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class DepthFirstTraversal {
static Stack<Tree> stack = new Stack();
public static void main(String[] args) {
Tree root = new Tree(1);
Tree l1 = new Tree(3);
Tree l2 = new Tree(9);
Tree l3 = new Tree(11);
Tree r1 = new Tree(5);
Tree r2 = new Tree(12);
Tree r3 = new Tree(13);
root.left = l1;
root.right = r1;
l1.left = l2;
l2.left = l3;
l3.right = r2;
l3.left = new Tree(14);
r2.right = r3;
Tree r4 = new Tree(88);
r1.right = r4;
dfs(root);
}
public static void dfs(Tree root) {
if (null == root) {
return;
}
//设置访问标记
root.isVisited = true;
//入栈
stack.push(root);
//访问结点
//开始弹栈
if (!stack.isEmpty()) {
Tree pop = stack.pop();
System.out.print(pop.value + "\t");
if (pop.left != null && !pop.left.isVisited) {
dfs(pop.left);
}
if (pop.right != null && !pop.right.isVisited) {
dfs(pop.right);
}
}
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/trees/GetPathsBySum.java
================================================
package cn.codepub.algorithms.trees;
import cn.codepub.algorithms.utils.Tree;
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
/**
* <p>
* Created with IntelliJ IDEA. 2015/10/30 16:38
* </p>
* <p>
* ClassName:GetPathsBySum
* </p>
* <p>
* Description:
* 题目:输入一棵二叉树和一个整数,打印出二叉树中结点值的和为输入整数的所有路径。
* 从树的根结点开始往下一直到叶结点所经过的结点形成一条路径。
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class GetPathsBySum {
static Stack<Tree> stack = new Stack();
static List<List<Tree>> pathsList = new ArrayList<>();
public static void main(String[] args) {
Tree root = new Tree(10);//给定的树
Tree l1 = new Tree(5);
Tree l2 = new Tree(4);
Tree r1 = new Tree(12);
Tree r2 = new Tree(7);
root.left = l1;
root.right = r1;
l1.left = l2;
l1.right = r2;
int num = 22;//给定的整数
dfs(root, new ArrayList<Tree>());
//这样就获取到了所有路径的集合
for (List<Tree> list : pathsList) {
int temp = 0;
for (Tree t : list) {
temp += t.value;
}
if (temp == num) {
System.out.println(list);
}
}
}
/**
* 使用变体的深度优先遍历,存储下来每一条路径
* 在压栈的时候,同时将结点加入链表,在弹栈的时候,先判断是否是叶子结点,是的话,则输出一条路径,然后直接移除此结点
*
* @param root
*/
public static void dfs(Tree root, List<Tree> path) {
if (null == root) {
return;
}
//设置访问标记
root.isVisited = true;
//入栈
stack.push(root);
//加入链表
path.add(root);
//开始弹栈
while (!stack.isEmpty()) {
//在弹栈的同时也要将该结点从路径中移除,但是在移除前要判断是否已经是一条完整的路径,如果是一条完整的路径,则存储之
Tree pop = stack.pop();
if (pop.left != null && !pop.left.isVisited) {
dfs(pop.left, path);
}
if (pop.right != null && !pop.right.isVisited) {
dfs(pop.right, path);
}
if (pop.left == null && pop.right == null) {
//说明到了叶子结点了
pathsList.add(new ArrayList<>(path));
}
path.remove(pop);//从一条路径中移除
}
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/trees/LevelTraverseBinaryTree.java
================================================
package cn.codepub.algorithms.trees;
import cn.codepub.algorithms.utils.Tree;
import java.util.ArrayDeque;
import java.util.Queue;
/**
* <p>
* Created with IntelliJ IDEA. 2015/10/30 13:38
* </p>
* <p>
* ClassName:LevelTraverseBinaryTree
* </p>
* <p>
* Description:二叉树的层次遍历
* 题目:从上往下打印出二叉树的每个结点,同一层的结点按照从左到右的顺序打印
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class LevelTraverseBinaryTree {
public static void main(String[] args) {
Queue queue = new ArrayDeque<>();
Tree root = new Tree(1);
Tree l1 = new Tree(3);
Tree l2 = new Tree(9);
Tree l3 = new Tree(11);
Tree r1 = new Tree(5);
Tree r2 = new Tree(12);
Tree r3 = new Tree(13);
root.left = l1;
root.right = r1;
l1.left = l2;
l2.left = l3;
l3.right = r2;
r2.right = r3;
levelTraverse(root, queue);
}
public static void levelTraverse(Tree root, Queue<Tree> queue) {
if (root == null) {
return;
}
queue.add(root);
while (!queue.isEmpty()) {
Tree remove = queue.remove();
System.out.print(remove.value + "\t");
if (remove.left != null) {
queue.add(remove.left);
}
if (remove.right != null) {
queue.add(remove.right);
}
}
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/trees/TraverseBinaryTree.java
================================================
package cn.codepub.algorithms.trees;
import cn.codepub.algorithms.utils.Tree;
/**
* <p>
* Created with IntelliJ IDEA. 2015/10/30 14:16
* </p>
* <p>
* ClassName:TraverseTree
* </p>
* <p>
* Description:提供对二叉树的三种遍历方式:先序遍历,中序遍历,后序遍历
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class TraverseBinaryTree {
public static void main(String[] args) {
Tree root = new Tree(1);
Tree l1 = new Tree(3);
Tree l2 = new Tree(9);
Tree l3 = new Tree(11);
Tree r1 = new Tree(5);
Tree r2 = new Tree(12);
Tree r3 = new Tree(13);
root.left = l1;
root.right = r1;
l1.left = l2;
l2.left = l3;
l3.right = r2;
r2.right = r3;
System.out.println("先序遍历");
preOrder(root);
System.out.println("\n中序遍历");
inOrder(root);
System.out.println("\n后序遍历");
postOrder(root);
}
public static void preOrder(Tree root) {
if (root == null) {
return;
}
System.out.print(root.value + "\t");
if (root.left != null) {
preOrder(root.left);
}
if (root.right != null) {
preOrder(root.right);
}
}
public static void inOrder(Tree root) {
if (root == null) {
return;
}
if (root.left != null) {
inOrder(root.left);
}
System.out.print(root.value + "\t");
if (root.right != null) {
inOrder(root.right);
}
}
public static void postOrder(Tree root) {
if (root == null) {
return;
}
if (root.left != null) {
postOrder(root.left);
}
if (root.right != null) {
postOrder(root.right);
}
System.out.print(root.value + "\t");
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/trees/VerifySequenceOfBST.java
================================================
package cn.codepub.algorithms.trees;
import java.util.Arrays;
/**
* <p>
* Created with IntelliJ IDEA. 2015/10/30 14:56
* </p>
* <p>
* ClassName:VerifySequenceOfBST
* </p>
* <p>
* Description:
* 题目:输入一个整数数组,判断该数组是不是某二叉搜索树的后序遍历结果,如果是则返回true,否则返回false
* 假设输入的数组的任意两个数字都互不相同
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class VerifySequenceOfBST {
public static void main(String[] args) {
int[] nums = new int[]{5, 7, 6, 9, 11, 10, 8};
boolean verify = verify(nums);
System.out.println(verify);
nums = new int[]{7, 4, 6, 5};
verify = verify(nums);
System.out.println(verify);
}
public static boolean verify(int[] sequences) {
if (null == sequences || sequences.length <= 1) {
return true;
}
int root = sequences[sequences.length - 1];
int index = 0;
//寻找左右子树的分割点
while (index < sequences.length && sequences[index] < root) {
index++;
}
//校验右子树应该是全大于root值
for (int i = index; i < sequences.length; i++) {
if (sequences[i] < root) {
return false;
}
}
boolean left = true;
//如果index==0,说明根节点之前所有元素都属于右子树,无需判断左子树
if (index > 0) {
left = verify(Arrays.copyOf(sequences, index));
}
boolean right = true;
//如果index>=length-1,根节点之前所有元素都属于左子树,无需判断右子树
if (index < sequences.length - 1) {
right = verify(Arrays.copyOfRange(sequences, index, sequences.length - 1));
}
return left && right;
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/utils/StackX.java
================================================
package cn.codepub.algorithms.utils;
/**
* <p>
* Created with IntelliJ IDEA. 2016/1/8 19:18
* </p>
* <p>
* ClassName:StackX
* </p>
* <p>
* Description:公用的自定义Stack,支持泛型操作
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class StackX<T> {
private int maxSize;
private Object[] stackArray;
private int top;
public StackX() {
}
public StackX(int s) {
maxSize = s;
stackArray = new Object[maxSize];
top = -1;
}
public void push(T j) {
stackArray[++top] = j;
}
public T pop() {
return (T) stackArray[top--];
}
public T peek() {
return (T) stackArray[top];
}
public boolean isEmpty() {
return (top == -1);
}
public int size() {
return top + 1;
}
public T peekN(int n) {
return (T) stackArray[n];
}
public void displayStack(String s) {
System.out.print(s);
System.out.print("Stack(bottom->top):");
for (int j = 0; j < size(); j++) {
System.out.print(peekN(j) + " ");
}
System.out.println();
}
}
================================================
FILE: src/main/java/cn/codepub/algorithms/utils/Tree.java
================================================
package cn.codepub.algorithms.utils;
/**
* <p>
* Created with IntelliJ IDEA. 2015/10/30 14:50
* </p>
* <p>
* ClassName:Tree
* </p>
* <p>
* Description:公用的树定义
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class Tree {
public Tree left;//左子树
public Tree right;//右子树
public int value;//结点值
public boolean isVisited;//是否访问
public Tree() {
}
public Tree(int value) {
this.value = value;
}
@Override
public String toString() {
return String.valueOf(this.value);
}
}
================================================
FILE: src/main/java/cn/codepub/patterns/core/DeepClone.java
================================================
package cn.codepub.patterns.core;
import java.io.*;
import java.util.Hashtable;
/**
* <p>
* Created with IntelliJ IDEA. 2015/11/8 21:43
* </p>
* <p>
* ClassName:DeepClone
* </p>
* <p>
* Description:implements a deep clone for yourself
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class DeepClone {
public static void main(String[] args) {
MyPerson son = new MyPerson("son", 1);
MyPerson myPerson = new MyPerson("father", 11);
myPerson.son = son;
try {
MyPerson deepClone = (MyPerson) myPerson.deepClone();
//修改原值
myPerson.son.name = "newSon";
//可以看到完成了深拷贝,拷贝的引用变量son的name属性并未更改
System.out.println(deepClone.son.name);
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
class MyPerson implements Cloneable, Serializable {
public String name;
public int age;
public MyPerson son;
public MyPerson(String name, int age) {
this.name = name;
this.age = age;
}
public MyPerson(String name, int age, MyPerson son) {
this(name, age);
this.son = son;
}
public Object deepClone() throws IOException, ClassNotFoundException {
ByteArrayOutputStream bo = new ByteArrayOutputStream();
ObjectOutputStream oo = new ObjectOutputStream(bo);
oo.writeObject(this);
ByteArrayInputStream bi = new ByteArrayInputStream(bo.toByteArray());
ObjectInputStream oi = new ObjectInputStream(bi);
return oi.readObject();
}
Hashtable hashtable = new Hashtable();
@Override
protected Object clone() throws CloneNotSupportedException {
MyPerson myPerson = null;
try {
myPerson = (MyPerson) super.clone();
myPerson.son = (MyPerson) son.clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
return myPerson;
}
}
================================================
FILE: src/main/java/cn/codepub/patterns/core/Singleton.java
================================================
package cn.codepub.patterns.core;
import java.util.HashSet;
import java.util.Set;
/**
* <p>
* Created with IntelliJ IDEA. 2015/10/22 13:55
* </p>
* <p>
* ClassName:Singleton
* </p>
* <p>
* Description:饿汉模式天生线程安全,而且实现简单,在此不予提供,本类为懒汉模式,使用双跳检测的多线程安全的单例模式
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class Singleton {
private Singleton() {
}
private static volatile Singleton singleton;
public static Singleton getInstance() {
if (singleton == null) {
synchronized (Singleton.class) {
if (singleton == null) {
singleton = new Singleton();
}
}
}
return singleton;
}
public static void main(String[] args) {
Set<Singleton> set = new HashSet<>();
for (int i = 0; i < 10; i++) {
Singleton singleton = Singleton.getInstance();
boolean add = set.add(singleton);
//可以看到除了第一次,之后每次获取的实例和第一次都是同一实例
System.out.println(add);
}
}
}
================================================
FILE: src/main/java/cn/codepub/patterns/proxy/CGLibProxyHandler.java
================================================
package cn.codepub.patterns.proxy;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
import java.lang.reflect.Method;
/**
* <p>
* Created with IntelliJ IDEA. 2015/10/21 22:16
* </p>
* <p>
* ClassName:CGLibProxyHandler
* </p>
* <p>
* Description:使用CGLib实现动态代理
* 为什么要有CGLib动态代理呢?因为JDK的动态代理机制只能代理实现了接口的类,而不能实现接口的类就不能实现JDK的动态代理,CGLib是针对类来实现代理的
* 它的原理是对指定的目标类生成一个子类,并覆盖其中方法实现增强,但因为采用的是继承,所以不能对final修饰的类进行代理
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class CGLibProxyHandler implements MethodInterceptor {
private Object tar;//被代理对象
/**
* @param tar 使用被代理对象
* @return 需要将返回结果强转成被代理对象
*/
public Object getInstance(Object tar) {
this.tar = tar;
Enhancer enhancer = new Enhancer();
//设置被代理对象为代理类的超类
enhancer.setSuperclass(this.tar.getClass());
//设置回调方法
enhancer.setCallback(this);
//创建代理对象
return enhancer.create();
}
/**
* 回调方法
*
* @param o
* @param method
* @param objects
* @param methodProxy
* @return
* @throws Throwable
*/
@Override
public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
System.out.println("before method invoke...");
System.out.println(method);
Object res = methodProxy.invokeSuper(o, objects);
System.out.println("after method invoke...");
return res;
}
@org.junit.Test
public void testCGLibProxy() {
System.out.println("-----------使用CGLib动态代理-----------");
CGLibProxyHandler cgLibProxyHandler = new CGLibProxyHandler();
Count count = (Count) cgLibProxyHandler.getInstance(new CountImpl());
count.queryCount();
count.updateCount();
}
}
================================================
FILE: src/main/java/cn/codepub/patterns/proxy/CountImpl.java
================================================
package cn.codepub.patterns.proxy;
/**
* 静态代理、JDK动态代理、CGLib代理的辅助类
*/
interface Count {
//定义查询账户方法
void queryCount();
//定义更新账户方法
void updateCount();
}
public class CountImpl implements Count {
@Override
public void queryCount() {
System.out.println("the method of query count...");
}
@Override
public void updateCount() {
System.out.println("the method of update count...");
}
}
================================================
FILE: src/main/java/cn/codepub/patterns/proxy/JDKProxyHandler.java
================================================
package cn.codepub.patterns.proxy;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
/**
* <p>
* Created with IntelliJ IDEA. 2015/10/21 20:11
* </p>
* <p>
* ClassName:ProxyHanlder
* </p>
* <p>
* Description:使用JDK实现的动态代理
* 动态代理的主要作用有三
* ① Proxy类的代码量可以得到控制,由静态代理可以看出,随着业务变得庞大,代理类也会变得庞大,而动态代理不会出现这种情况
* ② 可以实现AOP编程,其实Spring中的AOP就是一个很好的应用实例
* ③ 可以解耦合,通过参数传递的形式就可以判断真实类,而不需要事先实例化,从而更加灵活多变
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class JDKProxyHandler implements InvocationHandler {
private Object tar;
public JDKProxyHandler() {
}
public JDKProxyHandler(Object tar) {
this.tar = tar;
}
public Object bind(Object tar) {
this.tar = tar;
return Proxy.newProxyInstance(tar.getClass().getClassLoader(), tar.getClass().getInterfaces(), this);
}
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
Object result;
System.out.println("before method invoke...");
System.out.println("Method: " + method);
result = method.invoke(tar, args);
System.out.println("after method invoke...");
return result;
}
public static void testDynamicProxy() {
System.out.println("-----------使用JDK动态代理-----------");
Count count = (Count) new JDKProxyHandler().bind(new CountImpl());
count.queryCount();
count.updateCount();
}
public static void main(String[] args) {
testDynamicProxy();
}
}
================================================
FILE: src/main/java/cn/codepub/patterns/proxy/StaticProxyHandler.java
================================================
package cn.codepub.patterns.proxy;
/**
* <p>
* Created with IntelliJ IDEA. 2015/10/21 19:33
* </p>
* <p>
* ClassName:CountProxy
* </p>
* <p>
* Description:静态代理的实现
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class StaticProxyHandler implements Count {
private Count count;
//默认构造器
public StaticProxyHandler() {
}
//接收被代理类实例的构造器
public StaticProxyHandler(Count count) {
this.count = count;
}
@Override
public void queryCount() {
System.out.println("before method invoke...");
//调用委托类的方法
count.queryCount();
System.out.println("after method invoke...");
}
@Override
public void updateCount() {
System.out.println("before method invoke...");
//调用委托类的方法
count.updateCount();
System.out.println("after method invoke...");
}
public static void main(String[] args) {
testStaticProxy();
}
public static void testStaticProxy() {
System.out.println("-----------使用静态代理-----------");
CountImpl countImpl = new CountImpl();
StaticProxyHandler staticProxyHandler = new StaticProxyHandler(countImpl);
staticProxyHandler.queryCount();
staticProxyHandler.updateCount();
}
}
================================================
FILE: src/main/resources/cilin.txt
================================================
Aa01A01= 人 士 人物 人士 人氏 人选
Aa01A02= 人类 生人 全人类
Aa01A03= 人手 人员 人口 人丁 口 食指
Aa01A04= 劳力 劳动力 工作者
Aa01A05= 匹夫 个人
Aa01A06= 家伙 东西 货色 厮 崽子 兔崽子 狗崽子 小子 杂种 畜生 混蛋 王八蛋 竖子 鼠辈 小崽子
Aa01A07= 者 手 匠 客 主 子 家 夫 翁 汉 员 分子 鬼 货 棍 徒
Aa01A08= 每人 各人 每位
Aa01A09= 该人 此人
Aa01B01= 人民 民 国民 公民 平民 黎民 庶 庶民 老百姓 苍生 生灵 生人 布衣 白丁 赤子 氓 群氓 黔首 黎民百姓 庶人 百姓 全民 全员 萌
Aa01B02= 群众 大众 公众 民众 万众 众生 千夫
Aa01B03# 良民 顺民
Aa01B04# 遗民 贱民 流民 游民 顽民 刁民 愚民 不法分子 孑遗
Aa01C01= 众人 人人 人们
Aa01C02= 人丛 人群 人海 人流 人潮
Aa01C03= 大家 大伙儿 大家伙儿 大伙 一班人 众家 各户
Aa01C04= 们 辈 曹 等
Aa01C05@ 众学生
Aa01C06# 妇孺 父老兄弟 男女老少 男女老幼
Aa01C07# 党群 干群 军民 工农兵 劳资 主仆 宾主 僧俗 师徒 师生 师生员工 教职员工 群体 爱国志士 党外人士 民主人士 爱国人士 政群 党政群 非党人士 业内人士 工农分子 军警民 党政军民
Aa01D01@ 角色
Aa02A01= 我 咱 俺 余 吾 予 侬 咱家 本人 身 个人 人家 斯人
Aa02A02= 区区 仆 鄙 愚 鄙人 小人 小子 在下 不才 不肖
Aa02A03@ 老子
Aa02A04= 老朽 老汉
Aa02A05@ 老娘
Aa02A06@ 愚兄
Aa02A07= 小弟 兄弟
Aa02A08= 奴 妾 妾身 民女
Aa02A09= 朕 孤 寡人
Aa02A10= 职 卑职 下官 奴婢 奴才
Aa02A11= 贫道 小道
Aa02A12@ 贫僧
Aa02A13@ 下臣
Aa02B01= 我们 咱 咱们 吾侪 吾辈 俺们 我辈 咱俩
Aa03A01= 你 您 恁 而 尔 汝 若 乃 卿 君 公
Aa03A02= 老兄 仁兄 世兄 兄长 大哥
Aa03A03= 老弟 贤弟 仁弟 兄弟
Aa03A04= 大嫂 大姐 老大姐
Aa03A05= 阁下 足下 驾 同志 老同志
Aa03A06= 陛下 主公 大王 万岁
Aa03A07= 您老 你咯
Aa03B01= 你们 尔等
Aa03B02= 诸位 各位 诸君
Aa04A01= 他 她 彼 其 渠 伊 人家
Aa04B01= 他们 她们 他俩 她俩
Aa05A01= 自己 自家 自个儿 自各儿 自身 本身 自我 本人 小我 我 自 己
Aa05B01= 别人 旁人 他人 人家
Aa05B02= 谁 哪个 哪位 张三李四
Aa05B03@ 其他人
Aa05C01= 某人 某
Aa05D01@ 任何人
Aa05E01@ 克隆人
Aa06A01= 谁 孰 谁人 谁个 何人 哪个 哪位 何许人也
Aa06B01@ 有人
Ab01A01= 男人 男子 男子汉 男儿 汉子 汉 士 丈夫 官人 男人家 光身汉 须眉 壮汉 男士
Ab01A02= 爷儿 爷们 爷儿们
Ab01A03= 先生 子 君 郎 哥 小先生
Ab01B01= 女人 女子 女性 女士 女儿 女 娘 妇 妇女 妇道 妇人 女人家 小娘子 女郎 巾帼 半边天 娘子军 石女 红装 家庭妇女 农妇 才女
Ab01B02= 女流 女人家 妇道人家 娘儿们 妞儿
Ab01B03= 少妇 婆娘 婆姨 娘子 小娘子
Ab01B04= 姑娘 少女 丫头 千金 小姐 闺女 室女 姑子 黄花闺女 大姑娘 小姑娘 童女 老姑娘 春姑娘
Ab01B05@ 小姐
Ab01B06= 仕女 贵妇人 太太 夫人 少奶奶 奶奶 贵妇
Ab01B07= 贱人 祸水
Ab01B08@ 工青妇
Ab01B09@ 巧妇
Ab01B10= 村姑 农家女
Ab01B11@ 女中
Ab01C01= 男女 士女 儿女 红男绿女 男男女女 少男少女
Ab01D01@ 男女老幼
Ab02A01= 老人 老 老者 老汉 老翁 翁 长老 长者 遗老 耆老 叟 父 老头儿 老头子 老年人 老头 老记 中老年人 白发人 年长者
Ab02A02= 老朽 风中之烛 枯木朽株 朽木粪土
Ab02A03= 老寿星 寿星
Ab02A04= 公公 爷爷 老爷爷 老太爷 老爹 老公公 老爷子 老大爷 老人家 丈人 丈 老 老父 父老 寿爷
Ab02A05= 老奶奶 老太婆 老妪 妪 媪 老婆儿 老婆子 老妇
Ab02A06= 老太太 老婆婆 老大娘 姥姥 奶奶 阿婆 嬷嬷 老妈妈 老大妈
Ab02A07= 老家伙 老糊涂
Ab02A08@ 老太公
Ab02B01= 成年人 壮年人 大人 人 丁 壮丁 佬 中年人
Ab02C01= 老小 老少 大小 老幼 老老少少 白叟黄童 大大小小
Ab02C02# 遗老 遗少 遗老遗少 封建残余
Ab03A01= 青年人 青年 小伙子 青少年 后生 弟子 子弟 初生之犊 年青人 小伙 小青年 年轻人
Ab03A02= 知识青年 知青
Ab03A03@ 社会青年
Ab03A04= 少年人 少年 苗子 苗 年幼 未成年 未成年人
Ab03A05= 芝兰 龙驹 千里驹
Ab03A06# 待业青年 务工青年
Ab03A07# 男孩子 少男
Ab04A01= 婴儿 婴孩 婴 新生儿 产儿 赤子 乳儿 毛毛 小儿 早产儿 婴幼儿
Ab04A02= 宝宝 宝贝 乖乖 囡囡 小鬼 宝贝疙瘩 宝贝儿 小宝宝
Ab04A03# 女婴 男婴
Ab04A04@ 弃婴
Ab04A05@ 圣婴
Ab04B01= 儿童 孩童 稚童 童稚 童子 孩子 孩儿 孩子家 小儿 小人儿 雏儿 幼儿 娃儿 娃娃 娃子 小子 小小子 竖子 孺子 稚子 童蒙 幼 童 孩 小 孺 囡 小朋友 小不点儿 少年儿童 童男童女 报童 少儿 小孩 小孩子 幼童 小娃 文童 伢儿 女孩儿 毛孩子 小家伙
Ab04B02= 妞 妮子 妮儿 丫头 黄毛丫头 阿囡 女孩子 小妞 女童
Ab04B03= 顽童 小淘气 淘气鬼 孩子头 孩子王 淘气包
Ab04B04= 男童 男孩儿 童男
Ab04B05@ 学龄儿童
Ab04B06@ 山里娃
Ab04B07@ 农家娃
Ac01A01= 高个儿 高个子 大个儿 大个子 巨人 大汉 彪形大汉
Ac01A02= 细高挑儿 长子
Ac01B01= 矮子 矮个儿 矮个子 矬子 侏儒 小个子
Ac01C01@ 瓷人
Ac01C02@ 稻草人
Ac02A01= 胖子 大块头 胖小子 重者
Ac02A02@ 胖妞
Ac02B01= 瘦子 骨头架子
Ac03A01= 美女 美人 姝 娥 花 媛 佳人 丽人 仙人 天仙 仙子 仙女 玉女 淑女 嫦娥 西施 尤物 娇娃 佳丽 丽质 红颜 红粉 红袖 蛾眉 婵娟 绝色 国色 小家碧玉 倾国倾城 天香国色 国色天香 靓女 天生丽质
Ac03B01@ 美男子
Ac03C01= 丑八怪 夜叉
Ac03C02= 麻子 麻脸
Ac03C03= 秃子 癞子 瘌痢头
Ac03C04= 豁嘴 豁子 兔唇
Ac03C05= 结巴 结子 咬舌儿 大舌头
Ac03C06# 斜眼 少白头
Ac03D01@ 俊男靓女
Ac03E01@ 卡通人
Ac03E02# 唐老鸭 灰姑娘 白雪公主 狮子王
Ad01A01= 居民 居者 定居者 居住者
Ad01A02= 市民 城里人 城市居民 都市人
Ad01A03= 乡民 乡下人 乡巴佬
Ad01A04= 船民 水上居民
Ad01A05@ 山里人
Ad01A06@ 山妹
Ad01B01= 侨民 侨 侨胞 华人 华裔 台胞
Ad01B02# 外侨 华侨 归侨 难侨 港澳台侨 爱国华侨 台港澳侨
Ad01B03# 日裔 亚裔
Ad02A01= 本国人 国人 同胞
Ad02A02# 侨胞 难胞 港胞 台属
Ad02A03# 爱国同胞 爱国主义者 爱国者
Ad02B01= 外国人 外侨 外人 外族 洋人
Ad02B02= 洋鬼子 鬼子 老外
Ad02B03# 西人 意大利人 缅甸人 西方人 阿拉伯人 日本人 美国人 犹太人 捷克人 芬兰人 德国人 比利时人 苏格兰人 玻利维亚人 波兰人 波斯人 乌拉圭人 突尼斯人 土耳其人 阿尔巴尼亚人 奥地利人 澳大利亚人 巴比伦人 巴西人 智利人 委内瑞拉人 伊朗人 伊拉克人 约旦人 英国人 印度人 科威特人 墨西哥人 玛雅人 毛里求斯人 秘鲁人 黎巴嫩人 卢森堡人 肯尼亚人 塞尔维亚人 瑞士人 新加坡人 瑞典人 哥伦比亚人 希腊人 古巴人 荷兰人 吉普赛人 几内亚人 加拿大人 加纳人 尼泊尔人 欧洲人 尼日利亚人 白沟人 长野人 利比亚人 莫斯科人 库尔德人 西班牙人 犹太人 吉卜赛人 印第安人
Ad02B04# 非洲人 亚洲人
Ad02B05# 白人 白种人 黑人
Ad02C01= 外族人 外族
Ad02C02# 瑶民 藏胞 藏民 边民 佤族人 俄族人 藏族人 阿族人 客家人 苗女 京族 旗人 回民
Ad02C03@ 色目人
Ad02D01= 中国人 华人 炎黄子孙 唐人
Ad02D02# 南京人 益都人 青岛人 港人 焦作人 北京人
Ad02D03# 汉人 汉民
Ad02D04@ 东方人
Ad02E01@ 殖民
Ad02F01@ 外星人
Ad02G01@ 太空人
Ad03A01= 本地人 当地人 土著 土人 土著人
Ad03A02= 村里人 全村人
Ad03A03@ 家里人
Ad03B01= 外乡人 异乡人 他乡人 外地人 外省人 外来人 外族
Ad03B02@ 外来妹
Ad03B03# 移民 寓公
Ad03C01= 同乡 老乡 乡人 乡里 乡亲 邻里 乡党 父老乡亲 故乡人
Ae01A01= 职工 员工
Ae01B01= 职员 干部 员司 机关部 老干部 高干
Ae01B02= 公务员 勤务员 办事员
Ae01B03= 秘书 文牍 文书 书记 文秘
Ae01B04@ 抄写员
Ae01B05= 总务 庶务 管事
Ae01B06= 会计 会计师 帐房 出纳 出纳员 先生 成本会计 大会计
Ae01B07@ 推销员
Ae01B08= 掮客 经纪人 中人
Ae01B09= 从业员 营业员 售货员 伙计 店员
Ae01B10= 列车员 乘务员 乘员
Ae01B11@ 话务员
Ae01B12= 广播员 播音员
Ae01B13= 理发员 理发师 理发匠 美容师 美发师
Ae01B14= 空姐 空中小姐
Ae01B15= 消防人 消防员
Ae01B16@ 安全员
Ae01B17= 承运人 发运人
Ae01B18= 供给者 供应者
Ae01B19= 编选者 编委 编撰者
Ae01B20= 勘察者 勘探者 探索者
Ae01B21@ 保管人
Ae01B22# 科员 雇员 干事 参事
Ae01B23# 内勤 外勤
Ae01B24# 售票员 收发员 收购员 采购员 保管员 宣传员 打字员 向导员 讲解员 信贷员 业务员 协理员 教职员 咨询员 馆员 电管员 土管员 水管员 销售员 关员 交易员 导购员 报幕员 调研员 农技员 文工团员 发行员 客运员 司售人员 纪检员 质量监督员 书记员 网员 储蓄员 安检员 监察员 接线员 研究馆员 清洁员 观测员 侦查员 化验员 实验员 收费员 审查员 审计员 主办员 协办员 农机员 审核员 邮员 仲裁员 收款员 柜员 供销员 传销员 购销员 协调员 工作员 司线员 报靶员 促销员 营销员 直销员 检验员 报关员 作价员 保洁员 运管员 护林员 突击队员 缉私队员 调查员 检查员 观察员 监督员 巡视员 协理员 专管员 统计员 保安员 联防队员
Ae01B25# 制片人 拍片人 发行人 出品人
Ae01B26# 宣传工作者 传播者
Ae01B27# 监票人 监督者
Ae02A01= 工人 工 工友 老工人
Ae02A02= 工匠 匠人 匠 巧手 巧匠 手艺人 艺人 手工业者
Ae02A03= 老师傅 师傅
Ae02A04= 壮工 小工
Ae02A05= 短工 零工 临时工
Ae02A06= 苦工 苦力 劳工 雇工 劳务工
Ae02A07= 学徒工 徒工
Ae02A08= 木工 木匠
Ae02A09= 瓦工 泥工 瓦匠 泥瓦匠 泥水匠
Ae02A10= 石工 石匠
Ae02A11= 油漆工 漆工 油漆匠 漆匠 油匠
Ae02A12= 花匠 园丁 老圃 花工
Ae02A13= 画匠 画工 画师
Ae02A14= 成衣匠 裁缝
Ae02A15@ 刺绣工
Ae02A16= 鞋匠 皮匠
Ae02A17= 铁工 铁匠
Ae02A18@ 银匠
Ae02A19@ 车工
Ae02A20# 产业工人 农业工人 季节工 长工 月工 日工 男工 帮工 青工 童工 包身工 民工 合同工 临时工 农工 务工者 女工 义务工 替工 协议工 义工 信号工 正式工 外来工 血统工人 农民工 华工 助工
Ae02A21# 机工 铣工 刨工 锻工 铸工 钳工 电工 焊工 装配工 保全工 电焊工 技工 修理工 架子工 磨工 农电工 装卸工 翻砂工
Ae02A22# 矿工 河工 养路工 煤化工 钻井工 采油工 管道工 管工 基建工 建工
Ae02A23# 篾匠 铜匠 锡匠 小炉儿匠 线路工 重化工 森工 轮转工 维修工
Ae02A24# 工程建设者 社会主义建设者 建设者
Ae03A01= 海员 船员 水手 潜水员 蛙人
Ae03A02= 领航员 引水员 领港 领江 航海家 引水人
Ae03A03@ 大副
Ae03B01= 船夫 船工 船家 船户 船老大 老大 舟子 长年 水工 船东
Ae03B02= 舵手 掌舵 艄公 掌舵人
Ae03B03@ 纤夫
Ae03C01= 驾驶员 司机 驾驶者 车手 的哥 驼员 机手
Ae03C02= 飞行员 航空员 试飞员 空哥
Ae03C03= 宇航员 航天员
Ae03C04= 驭手 御手 掌鞭 车把式 车夫 车把势
Ae03C05= 操作员 操纵员
Ae03C06@ 非司机
Ae03C07# 骑车人 推车人
Ae03D01= 搬运工 挑夫 脚夫 脚力 脚行 苦力 红帽子
Ae04A01= 炊事员 厨师 厨子 大师傅 庖 炊事 主厨 名厨
Ae04B01= 火夫 司炉 生火 伙夫 火头军
Ae05A01= 邮递员 邮差 信差 信使 绿衣使者 通信员 投递员
Ae05A02= 交通员 交通 通讯员
Ae05A03= 联络员 联络官 联系人
Ae05B01= 门房 号房 传达 门子 阍者 看门人 看门 门卫 守备
Ae06A01= 服务员 招待员 伙计 侍应生 侍者 茶房 女招待 服务生
Ae06A02= 堂倌 酒家 店家 跑堂儿的 店小二
Ae06A03@ 接待员
Ae06A04@ 值班员
Ae06B01= 清洁工 清道夫 清扫工
Ae06C01= 勤杂工 工友 茶房 勤杂人员
Ae07A01= 农民 农夫 农 庄稼人 庄稼汉 泥腿子 农家 老乡 村夫 庄户人 村民 庄浪人 庄户人
Ae07A02= 小农 老农
Ae07A03= 佃农 佃户
Ae07A04= 上中农 富裕中农
Ae07A05# 菜农 棉农 茶农 烟农 蔗农 花农 药农 林农 姜农 渔户 菇农 枣农 麦农 桔农 蚕农 果农 瓜农
Ae07A06# 雇农 贫农 下中农 中农 上中农 富农 贫下中农 贫雇农
Ae07A07# 自耕农 半自耕农
Ae07B01= 牧民 牧人 牧工 牧女 牧户 游牧民
Ae07C01= 渔民 渔翁 渔家 渔夫 渔父 打鱼郎
Ae08A01= 猎手 猎人 猎户 弓弩手
Ae08B01= 樵夫 樵 刍荛 樵姑
Ae08C01= 饲养员 倌 饲养户
Ae08C02= 羊倌 羊工 牧羊人
Ae08C03= 放牛郎 牛郎 牧童 放牛娃 牛倌
Ae08C04@ 猪倌
Ae08C05= 马夫 马倌
Ae08C06= 屠夫 屠户
Ae09A01= 商人 商贩 买卖人 商贾 贾 商 市侩 经纪人 生意人 巨商 商户 下海者
Ae09A02= 商旅 行商 行贩 单帮 倒爷
Ae09A03@ 货郎
Ae09A04= 小贩 摊贩 贩子 小商 小商贩 二道贩子
Ae09A05= 客帮 客商 客人 客
Ae09A06= 卖家 卖方 发包方 卖主
Ae09A07# 外商 官商 坐商 私商 批发商 投资者 制造商 中间商 珠宝商 粮商 对外商 零售商 经销商 厂商 推销商 销售商 运销商 售房方 房地产商 证券商 券商 生产商 开发商 发展商 交易商 出口商 进口商 供应商 赞助商 承包商 拍卖商 保险商 代理商 传销商 法商 书商 军火商 酒商 出版商 家具商
Ae09A08# 粮贩子 票贩子 票贩 棉贩子 菜贩 车贩子
Ae09A09# 个体户 运输户 专业户 面包户
Ae09A10# 台商 日商 美商 港商 侨商
Ae09A11# 交易者 发行者 出版者
Ae09A12@ 办报人
Ae10A01= 军官 武官 官佐 官长
Ae10A02= 指挥员 指挥官
Ae10A03= 总司令 司令员 统帅 主帅 元帅 大元帅 大将军 主将 元戎 将帅 帅 麾下 老帅 司令 司令官
Ae10A04= 将领 将军 大将 将 名将 武将 战将 儒将 名将 良将 爱将
Ae10A05= 副将 偏将 裨将
Ae10A06@ 宿将
Ae10A07= 虎将 猛将 闯将 骁将 枭将 飞将军 强将 悍将
Ae10A08= 老总 长官 警官
Ae10A09@ 带兵人
Ae10A10# 将官 校官 尉官 士官
Ae10A11# 大元帅 元帅 大将 上将 中将 少将 准将 大校 上校 中校 少校 大尉 上尉 中尉 少尉 准尉
Ae10A12# 司令员 参谋长 军长 师长 旅长 团长 营长 连长 排长 政委 教导员 指导员 副官 总参谋长 军士长
Ae10A13# 一百单八将 杨家将 中郎将 精兵强将
Ae10B01= 将士 官兵 将校 指战员
Ae10C01= 军人 武人 武夫 兵 兵家
Ae10C02= 荣誉军人 荣军
Ae10C03= 边防军 戍边人
Ae10C04@ 敌军
Ae10C05@ 伪军
Ae10C06@ 美军
Ae10D01= 士兵 兵士 战士 士卒 兵卒 兵丁 兵员 战斗员 大兵 老总 兵 卒 兵油子 匪兵 老弱残兵 精兵 卒子 新兵 小将 老将 虾兵蟹将 兵工
Ae10D02= 女兵 娘子军
Ae10D03= 士 军士
Ae10D04= 步兵 陆军
Ae10D05= 骑兵 轻骑 铁骑 骑士
Ae10D06= 水兵 水师 水军 海军
Ae10D07= 侦察兵 侦察员 尖兵 探子 便衣
Ae10D08= 哨兵 卫兵 岗哨 步哨
Ae10D09= 航空兵 空军
Ae10D10= 伞兵 空降兵
Ae10D11= 工兵 工程兵
Ae10D12= 号兵 司号员
Ae10D13= 警卫员 警卫 护兵 护卫 马弁 亲兵 卫士
Ae10D14= 通信员 勤务兵
Ae10D15= 退伍兵 退伍军人
Ae10D16= 复员军人 转业军人
Ae10D17= 老兵 老红军 老八路 红军
Ae10D18= 兵圣 战神
Ae10D19@ 游击队员
Ae10D20= 官军 官兵们
Ae10D21@ 海陆空
Ae10D22# 上士 中士 下士
Ae10D23# 列兵 上等兵 班长
Ae10D24# 铁道兵 炮兵 装甲兵 防化兵 雷达兵 通信兵 特种兵 宪兵 民兵 标兵 子弟兵 爆破手 红卫兵 红小兵 狙击手 排头兵 炮兵群 炮手 测绘兵 射手 志愿兵 汽车兵 枪手 点炮手 基干民兵 轻骑兵 轻兵 文艺兵
Ae10D25@ 坦克师
Ae11A01= 情报员 谍报员 间谍 特务 特工 特 细作 坐探 探子 眼线 眼目 耳目 信息员 克格勃 物探 通谍
Ae11A02= 敌特 敌探 奸细
Ae11B01= 译电员 分析员
Ae11C01@ 预报员
Ae12A01= 警察 警 巡警 巡捕 警士 警官 警员 警力 军警宪特 处警
Ae12A02= 人民警察 民警 公安人员
Ae12A03= 捕头 警长 探长
Ae12A04= 侦探 暗探 密探 包探 警探
Ae12A05= 看守 狱卒 狱吏 警监
Ae12A06= 行刑队 刽子手 刀斧手
Ae12A07@ 女警
Ae12A08@ 公安军
Ae12A09# 路警 岗警 门警 法警 刑警 户籍警 交通警 乘务警 水上警察 乘警 干警 交警 水警 狱警 治安警 特警 军警 海警 骑警 税官 片警 片儿警 森警 税警
Ae12B01= 审判员 审判员 陪审员 承审员 法官 推事 审判官 大法官 司法员 执法者 铁法官 司法官
Ae12B02= 检察官 检察员 检查官
Ae12B03@ 陪审团
Ae12B04# 提案人 申诉人
Ae12C01= 律师 辩护律师 辩护士 辩士 辩护人
Ae12C02@ 讼棍
Ae12D01= 征稽 考稽 税稽 税务员
Ae13A01= 教师 老师 师 导师 师长 师资 教员 园丁 先生 教书匠 讲师 教工 教职工 良师 民办教师 教育工作者 教育者 名师
Ae13A02= 教官 教练 教练员 教头 主教练
Ae13A03@ 班主任
Ae13A04= 教养员 保育员 阿姨
Ae13A05= 塾师 师傅 老夫子 业师 夫子
Ae13A06@ 宗师
Ae13A07@ 严师
Ae13A08@ 恩师
Ae13A09@ 督学
Ae13A10# 教授 副教授 讲师 助教 辅导员 正副教授 特教 客座教授 博导
Ae13A11# 博士 硕士 学士 副博士
Ae13B01= 学生 生 学员 学童 桃李 学习者
Ae13B02= 门生 门下 门徒 受业 学子 弟子 徒弟 入室弟子
Ae13B03= 高足 高徒 高材生 得意门生 高才生
Ae13B04@ 公费生
Ae13B05@ 走读生
Ae13B06= 寄宿生 住读生 住校生
Ae13B07= 定向招生 委培生 定向生
Ae13B08@ 择校生
Ae13B09@ 值日生
Ae13B10@ 受试者
Ae13B11@ 报考者
Ae13B12# 男生 女生 新生 老生 考生 劣等生 毕业生 肄业生 三好生 在校生 优等生 后进生 特长生 贫困生 特困生 受助生 双特生 双差生 优秀生 工读生 自费生 保送生
Ae13B13# 小学生 中学生 大学生 进修生 研究生 留学生 函授生 旁听生 实习生 见习生 博士生 插班生 初中生 大专生 硕士生 研修生 预备生 中小学生 高中生 本专科生 大中小学生 大中学生 中专生 留学人员
Ae13B14# 理科生 文科生
Ae13B15# 技校生 师范生
Ae13C01= 学习者 学人
Ae13C02@ 初学者
Ae13C03@ 见习员
Ae14A01= 运动员 选手 健儿
Ae14A02@ 中继者
Ae14A03@ 种子选手
Ae14A04# 种子 健将 非种子选手
Ae14A05# 前锋 中锋 左锋 右锋 中卫 前卫 右卫 后卫 边锋 射手 守门员 门将 锋线
Ae14A06# 二传手 主攻手 得分手 投手
Ae14A07# 削球手 球手 国脚 骑手 潜水员 球员 拳击手 陪练 滑冰者 相扑
Ae14A08@ 飞人
Ae14B01= 裁判员 裁判 评委
Ae14B02# 国际裁判 国家裁判
Ae14B03# 巡边员 记分员 计时员
Ae14B04@ 解说员
Ae14C01@ 评论员
Ae15A01= 医生 医师 医 大夫 郎中 先生 白衣战士 卫生工作者
Ae15A02= 国医 中医 中医师
Ae15A03= 良医 名医 神医
Ae15A04= 太医 御医
Ae15A05@ 法医
Ae15A06# 世医 儒医 庸医
Ae15A07# 西医 牙医 兽医 军医 校医 赤脚医生 游医 中西医 藏医 队医 保健医
Ae15A08# 主任医师 主治医师 住院医师 医士 主治医生 主刀
Ae15B01= 助产士 接生员 收生婆 产婆 老娘 姥姥
Ae15C01= 护士 看护 卫生员 看护者
Ae16A01= 作者 笔者 撰稿人 写稿人 著者 起草人
Ae16A02= 执笔人 主笔
Ae16A03@ 叙述者
Ae16B01= 译者 翻译 译员 通译
Ae16C01= 记者 新闻记者
Ae16C02= 新闻工作者 新闻官
Ae16C03@ 通讯员
Ae16C04= 媒体 传媒
Ae16D01= 编辑 编者 编辑者 编写者 编辑家 名编辑 美编 编导者
Ae16D02= 总编辑 总编
Ae16D03@ 编审
Ae16E01= 创意者 创意人
Ae17A01= 演员 艺人 优伶 戏子 优 伶 艺员 饰演者 表演者 扮演者
Ae17A02= 明星 影星 星 超巨星 超新星 大腕
Ae17A03= 女演员 坤角儿 女星
Ae17A04= 歌手 歌姬 歌舞伎 伎 歌者 歌星 演唱者 唱工 唱头
Ae17A05= 主角 角儿 正角儿
Ae17A06= 配角 班底 龙套 武行
Ae17A07@ 反派
Ae17A08= 名角 名伶 名优 红角
Ae17A09= 生角 生
Ae17A10= 老生 须生 外 末
Ae17A11= 旦角儿 旦 花衫 花旦 旦角 名旦
Ae17A12= 青衣 正旦
Ae17A13= 彩旦 丑婆子
Ae17A14= 丑角 小丑 丑 小花脸 三花脸 金小丑
Ae17A15= 花脸 净角 净 架子花
Ae17A16= 大花脸 大面 黑头 铜锤
Ae17A17= 二花脸 武二花
Ae17A18@ 武丑
Ae17A19@ 斗牛士
Ae17A20= 演职员 演职人员
Ae17A21= 表演家 表演艺术家
Ae17A22= 舞者 舞星
Ae17A23@ 司号
Ae17A24= 知名演员 名演员
Ae17A25@ 优弧
Ae17A26# 小生 娃娃生 武生 红生 文丑 红净
Ae17A27# 老旦 武旦 小旦 刀马旦
Ae17A28# 笑星 童星
Ae17B01= 琴师 乐师 乐手
Ae17B02= 鼓师 鼓手
Ae17B03= 号手 吹鼓手 吹号者
Ae17B04= 演奏者 演奏员
Ae17B05@ 小提琴手
Ae17C01= 剧团人员 剧中人
Ae17C02= 编剧 剧作者
Ae17C03# 原作 改编 编导 导演
Ae17C04@ 指挥
Ae17C05# 灯光 道具 效果 服装 化装 特技 场记
Ae17C06# 剧务 检场
Ae17C07# 摄影 录音 摄影师
Ae17C08@ 化妆师
Ae17D01@ 文学工作者
Ae17D02= 文艺工作者 艺术工作者
Ae17D03@ 音乐人
Ae17E01= 模特 模特儿
Ae17E02@ 名模
Ae17E03@ 洋模特
Ae18A01= 阴阳家 阴阳生
Ae18A02@ 算命先生
Ae18A03= 魔法师 魔术师
Ae18A04@ 天师
Ae18B01= 巫师 巫神 神巫 师公 巫 神汉
Ae18B02= 女巫 巫婆 神婆 仙姑
Ae18C01@ 天老儿
Ae18D01@ 预言家
Af01A01= 劳动者 生产者 小生产者
Af01A02= 无产者 无产阶级
Af01A03@ 无党派人士
Af01A04= 实施者 执行者
Af01A05# 就业者 从业者 失业者 自由职业者 再就业者 求职者 退休者 改革者
Af01A06# 马克思主义者 国际主义者 社会主义者 革命者 唯物主义者 唯心主义者 无神论者 辩证唯物论者 辩证唯物主义者 现实主义者 浪漫主义者 理想主义者 民族主义者 军国主义者 保护主义者
Af01A07# 壮劳力 半劳动力
Af01A08# 白领 蓝领
Af01A09# 打工族 打工妹 打工仔 务工人员
Af01A10# 上班族 工薪族
Af01A11@ 双职工
Af01A12# 收入者 高收入者 中低收入者 低收入者
Af01B01= 奴隶 农奴 娃子 奚 臧
Af01B02@ 被管理者
Af01C01= 小市民 城市贫民
Af01C02@ 拆迁户
Af01C03= 上访者 来访者
Af01C04= 接访 受访者
Af01C05= 投保人 股民
Af01D01= 候选人 候选者 应选人
Af01E01= 选民 选择者 选举人 投票者
Af01F01= 跟随者 追随者 支持者 拥护者 维护者
Af01G01= 反驳者 反对者
Af01G02= 抗议者 示威者 游行者
Af01G03@ 要求者
Af01H01@ 竞投人
Af02A01= 仆人 佣人 下人 奴仆 奴婢 仆役 家丁 家奴 当差 差役 雇工 佣工 公仆 孺子牛 繇
Af02A02= 男仆 苍头
Af02A03= 童仆 家童 书童 小厮 竖子 马童 扈
Af02A04= 女仆 仆妇 女佣 女佣人 老妈子 妈 保姆 娘姨 阿姨 女奴
Af02A05= 婢女 婢 丫鬟 丫头 使女 青衣 侍女 妮子
Af02A06= 奶妈 奶娘 奶子 乳母 嬷嬷 乳娘
Af02A07@ 管家
Af02A08= 奴才 小人 看家狗 犬马
Af02A09@ 轿夫
Af02A10@ 更夫
Af02B01= 仆从 长随 跟班 跟脚 伙计
Af02B02= 侍从 扈从 侍者
Af02B03= 随从 随员 左右 随行人员
Af03A01= 封建主 领主
Af03A02@ 封建把头
Af03B01= 地主 二地主 庄园主 恶霸地主 田主 恶霸地主 东佃
Af03B02= 东家 老爷 少东家
Af03B03= 农奴主 奴隶主 雇主
Af03B04@ 剥削者
Af03C01= 士绅 绅士 乡绅 官绅 缙
Af03C02@ 开明绅士
Af03C03= 豪绅 劣绅 土豪劣绅 土豪 员外
Af04A01= 资本家 资产阶级 财阀 寡头 大王 财政寡头 金融寡头 资产者 有产者 放贷人
Af04A02= 老板 财东 业主 小业主 老板娘 行东
Af04A03= 店主 店家 少掌柜 掌柜 甩手掌柜
Af04A04= 经营者 纳税人
Af04A05@ 冠名者
Af04A06= 出资人 投资人
Af04A07@ 民族资产阶级
Af04A08# 董事 股东 董监事 常务董事
Af04A09# 参展商 投资商 玩具商 盗版商 服务商 承销商 经商者
Af04A10# 贷款人 收款人 存款人 高利贷者 垄断者 投资方 输出方 出资者
Af04A11# 班组长 包工头 场主 出租人 承租人 承包人
Af04A12# 实干家 生产经营者 企业经营者 产业群体
Af05A01= 皇帝 帝 王 上 君 天子 天皇 帝王 君王 国王 国君 君主 当今 皇上 圣上 陛下 主公 九五 九五之尊 可汗 单于 大帝 沙皇 天骄 天王 五帝 太岁 王者 至尊 统治者
Af05A02= 女皇 女王
Af05A03= 暴君 桀纣
Af05A04@ 昏君
Af05A05# 摄政王 亲王
Af05A06# 唐宗 宋祖 明太祖 光绪帝 汉武帝 尧
Af05A07# 梁王 楚王 燕王
Af05A08@ 喾
Af05B01@ 后妃
Af05B02= 皇后 王后 娘娘
Af05B03= 妃子 贵妃 王妃 妃
Af05B04= 贵人 后宫 嫔妃
Af05B05@ 第一夫人
Af06A01= 皇室 王室 皇家 皇亲国戚 宗室
Af06A02@ 太上皇
Af06A03= 太后 皇太后 老佛爷
Af06A04= 太子 皇太子 东宫 储君 皇储 殿下 春宫 王储
Af06A05= 王子 皇子
Af06A06= 公主 郡主
Af06A07@ 驸马
Af06A08= 王孙 金枝玉叶 琼枝玉叶 玉叶金枝
Af06B01= 王公 公爵 王爷 千岁爷 亲王 千岁 诸侯
Af06C01= 贵族 万户侯 大公
Af06C02= 权贵 显贵 显要 贵人
Af06C03@ 贵胄
Af06C04@ 王官
Af06D01@ 臣民
Af06D02@ 诤臣
Af06D03@ 君臣
Af07A01= 太监 宦官 公公 老公公 阉人
Af07A02@ 三宝
Af07B01= 宫女 宫娥
Af07C01= 女官 女史 女宫
Af08A01= 官吏 臣子 臣僚 臣 官 吏 官长 官僚 官府 父母官 群臣 官儿 官宦 命官 地方官 官爵
Af08A02= 大臣 重臣 大吏 达官 当道 大员 三九 三朝元老 高官贵爵 达官贵人 高官厚禄 鼎
Af08A03= 芝麻官 知府 县令
Af08A04= 忠臣 忠良
Af08A05= 奸臣 坏官
Af08A06= 清官 青天 廉吏 廉者
Af08A07= 赃官 贪官 贪官污吏 饕餮之徒
Af08A08@ 胥吏
Af08A09= 差役 公差 公人 皂隶 衙役 走卒 听差 杂役
Af08A10@ 太保
Af08A11@ 次官
Af08A12# 文官 武官 刺史 地保 都督 督办 督抚 翰林 史官 侍郎 太守 提督 县官 巡抚 知县 总督 保甲 外交官 知事 外交大臣 主考官 执行官 执政官 州督 港督 石油大臣 主官 考官
Af08A13@ 酷吏
Af08A14@ 不管部长
Af08B01@ 政客
Af08B02# 议员 常务委员 朝臣 立法委员
Af09A01= 宰相 丞相 上相 首相 相公 中堂 尚书
Af09B01@ 中式者
Af09B02@ 状元
Af09B03@ 举人
Af09B04= 秀才 生员
Af09B05# 状元 榜眼 探花 进士 举人 会元 秀才
Af09C01= 幕宾 幕僚 师爷 老夫子 阁僚
Af09D01= 门客 门下 食客 篾片 帮闲 马前卒
Af09E01= 使者 使节 使命 使 行使 大使 行李 说者
Af09E02# 务使 密使 特命全权大使 节度使 观察使
Af10A01= 领袖 元首 首领 首脑 主脑 法老 资政 特首
Af10A02= 头领 头脑 头子 头目 头儿 头头 把头 大王 魁首 魁 酋 头人 带头人 领头雁 领导干部 党首 领导人 决策人 当权者
Af10A03= 控制者 操纵者 掌握者
Af10A04# 主席 总统 首相 总理 总裁 委员长 总书记 大总统 代总理 内阁总理 代总统 总督 国父
Af10A05# 党魁 霸主 会首
Af10A06# 酋长 土司 族长 盟主 寨主 敌酋 盟长
Af10A07# 阿拉法特 伊丽莎白 林肯 马歇尔 密特朗 伊万诺夫 穆罕默德 贝布托 吐谷浑 戴高乐 马克思 布什 杜鲁门 赫鲁晓夫 克林顿 肯尼迪 里根 列宁 罗斯福 拿破仑 尼克松 邱吉尔 撒切尔 斯大林 苏丹 希特勒 叶利钦
Af10A08# 李瑞环 彭德怀 钱其琛 乔石 宋庆龄 邓小平 江泽民 蒋介石 李鹏 刘邦 刘少奇 毛泽东 孙中山 周恩来 朱德 李先念 李鹏
Af10A09@ 慈禧
Af10B01= 领导 负责人 首长 长官 主管 主任 第一把手 官员 决策者 管理者 企业主 企业管理者 领导人员 领导者 经营管理者
Af10B02= 领队 总指挥 组织者 指挥者 管理员 大班 总指挥员 管理人
Af10B03= 监工 工头 拿摩温 矿长 工段长 工长 带工头 监管者 总监
Af10B04# 部长 司长 局长 厅长 处长 科长 股长 组长 班长 外交部长 国防部长 财政部长 外长 外相 卫生部长 新闻部长 台长 署长 党小组长 柜组长 代部长 分局长 班主 课长 卫队长 大队长 队长 分队长 支队长 总队长 小组长 内政部长 交通部长 宣传部长 文化部长 组织部长 武装部长 军事部长 经济部长 事务部长 司法部长 厅局长
Af10B05# 省长 市长 县长 区长 乡长 村长 保长 家长 镇长 州长 乡镇长 代省长 代市长 省市长 公安局长 管理局长
Af10B06# 厂长 校长 院长 馆长 行长 所长 社长 庭长 探长 检察长 站长 船长 轮机长 机长 列车长 事务长 护士长 场长 司务长 审计长 干事长 财长 院校长 室长 舰长
Af10B07# 经理 襄理 协理 总经理 副总
Af10B08# 会长 董事长 理事长 秘书长 书记长
Af10B09# 大使 公使 领事 代办 参赞 武官 一秘 二秘 专员
Af10B10# 带班 领班
Af10B11@ 官房长官
Af10B12# 党支书 党委书记 团干部
Af10B13# 支书 村官 村干部 村支书 村主任 生产队长
Af10B14# 部级 部长级 部头
Af10B15# 裁判长 议长 次长 众议长 参议长
Af10B16# 系主任 室主任 教务长 学监 园长
Af10C01= 创建者 创立者 创建人 创作者 缔造者 开创者 主创者 奠基人
Af10C02= 创业者 创业人
Af10C03= 策划人 策划者 规划者
Af10D01= 首倡者 首创者 领头人
Af10D02= 倡导者 倡议者 发起人 提出者
Af10D03@ 推动者
Af10D04= 主办人 主办者
Af10D05= 经办人 经办人员
Af11A01= 名人 名流 名士 名家 名宿 闻人 先达 知名人士 头面人物 风云人物 风流人物 政要 球星 巨星 名匠 社会名流
Af11A02= 要人 要员 巨头 大亨 大人物
Af11A03@ 成功者
Af11A04# 泰戈尔 爱迪生 释迦牟尼 巴赫 居里 哥伦布 赫兹 贝尔
Af11A05@ 加加林
Af11A06# 艾森豪威尔 戴高乐 拿破仑 希特勒 恩格斯 约翰逊
Af11A07# 李时珍 白求恩
Af11A08# 巴尔扎克 达尔文 杜甫 郭沫若 鲁迅 茅盾 屈原
Af11A09@ 道格拉斯
Af11A10# 考茨基 罗伯特 马尔萨斯 密特朗 图曼斯基 贝多芬 约翰逊
Af11A11# 华罗庚 钱学森 徐海 爱因斯坦 多普勒 牛顿 诺贝尔 安培 巴甫洛夫 达尔文 哥白尼 加里波第 居里夫人 考茨基 马尔萨斯 牛顿 伽利略 李四光 钱学森 杨振宁
Af11A12# 孔子 孟子
Af11A13# 齐白石 徐悲鸿
Af11A14# 包公 项羽
Af11B01= 隐士 逸民 处士 山民 隐君子
Af11C01= 小人物 老百姓 无名氏 无名小卒 无名之辈 小卒 普通人
Ag01A01= 健康人 好人 正常人 常人 平常人
Ag01A02@ 活人
Ag01B01= 病人 病家 病员 病号 患者 病夫 病包儿 药罐子 病秧子 患儿
Ag01B02= 植物人 瘫子
Ag01B03@ 带菌者
Ag01B04@ 中毒者
Ag01C01= 疯子 疯人 痴子 狂人 神经病
Ag01D01@ 吃瓜人
Ag02A01= 伤员 伤号 彩号 伤兵 伤病员 受伤者 伤者 受难者 伤亡者 伤残人员
Ag02B01= 残废 残缺 废人 非人 残疾人 伤残人 智残人 畸形儿
Ag02B02= 跛子 瘸子 拐子 跛脚 瘸腿
Ag02B03= 驼子 驼背 罗锅儿
Ag02B04= 瞎子 盲人 瞍 盲童
Ag02B05@ 独眼龙
Ag02B06@ 聋子
Ag02B07= 哑巴 哑子 哑女
Ag02B08@ 两性人
Ag02B09@ 聋哑人
Ag02C01= 孕妇 妊妇 双身子 大肚子 产妇 孕产妇
Ag03A01= 鳏寡孤独 孤寡 孤儿寡妇
Ag03A02= 鳏夫 孤老 孤寡老人
Ag03A03= 寡妇 孀妇 遗孀 望门寡
Ag03A04= 孤 孤儿 遗孤 弃儿
Ag03A05@ 遗腹子
Ag03A06= 孤魂 孤鬼 独夫
Ag03A07= 光杆儿 光杆司令 孤家寡人 独个儿 单干户 单人
Ag03A08= 单身汉 独身汉 光棍儿 单身者
Ag03A09@ 寂寞者
Ag03A10@ 老处女
Ag04A01= 富翁 财主 财东 老财 阔老 大户 大腹贾 暴发户 富豪 豪富 有钱人 财神 财神老爷 富人 富家 大款 富人 富家 巨贾 豪商巨贾 万元户 巨富 百万富翁 富商
Ag04A02= 阔少 大少爷 小开
Ag04A03= 债主 债权人
Ag04A04= 吸血鬼 寄生虫
Ag04B01= 穷人 穷鬼 穷光蛋 穷棒子 寒士 贫民 穷骨头 贫困者
Ag04B02@ 饥民
Ag04B03= 乞丐 乞 丐 花子 叫花子 要饭的 乞讨者 跪丐
Ag04B04= 债户 负债人 借债人 债务人 欠款人 借款人
Ag04B05= 帮扶户 保户
Ag04C01@ 大忙人
Ag04D01= 闲杂人员 无聊者
Ag05A01= 幸运儿 福人 福将 福星 不倒翁 天之骄子 骄子 幸运者
Ag05A02@ 幸存者
Ag05A03@ 获奖者
Ag05B01= 红人 宠儿 嬖 大红人
Ag06A01= 可怜虫 小可怜儿 叩头虫
Ag06A02= 无辜 俎上肉 被冤枉者
Ag06A03= 出气筒 受气包
Ag06A04# 泪人儿 弃儿 亡国奴
Ag06B01= 瓮中之鳖 网中之鱼 涸辙之鲋
Ag06C01= 众矢之的 过街老鼠 怨府 落水狗
Ag07A01= 屈死鬼 冤魂 怨鬼
Ag07B01= 被害人 受害人 事主 被害者 受害者 遇害者
Ag07B02@ 苦主
Ag07B03= 当事人 当事者
Ag07B04# 求援者 上当者 遇险者
Ag07B05@ 挨斗者
Ag07C01= 冤大头 大头
Ag07C02= 替身 替死鬼 替罪羊 牺牲品 垫脚石
Ag07D01= 祸胎 祸根 祸端
Ag07D02= 火主 火头
Ag07E01= 死难者 罹难者 莩
Ag08A01= 难民 难胞 难侨
Ag08B01= 灾民 流民
Ag08C01= 逃亡者 逃犯 亡命
Ag08C02@ 偷渡者
Ag08D01= 流浪汉 游民 流民 浪人 无家可归者 流浪者 瘪三 无业游民
Ag09A01= 败兵 乱兵 残兵 散兵 散兵游勇 残兵败将 余部
Ag09A02@ 败将
Ag09B01= 俘虏 俘 伤俘 战俘 活口 舌头 囚
Ag09B02= 人质 质子 质 肉票
Ag09C01= 违反者 违者 违章人
Ag09D01= 不合格者 不符合条件者
Ag09D02@ 符合条件者
Ag09E01= 输家 失败者 输者
Ag10A01= 旅客 客人 旅人 游子 行人 行者 行旅 客
Ag10A02= 过路人 过客
Ag10A03= 游人 游客 旅游者 观光者 港客 观光客 旅行者 漫游者 旅行家 度假者 游士
Ag10A04= 乘客 司乘人员
Ag10A05@ 步行者
Ag10A06= 参观者 观赏者
Ag10B01@ 询问者
Ah01A01= 亲戚 亲属 本家 亲眷 六亲 戚 亲族 氏 亲朋好友
Ah01A02@ 尊亲
Ah01A03@ 舍亲
Ah01A04= 外戚 远房
Ah01A05= 血亲 宗亲
Ah01A06@ 至亲
Ah01A07= 姻亲 亲家 远亲 葭莩 葭莩之亲
Ah01A08# 近亲 内亲 干亲 表亲 姑表亲 老亲 长亲 远房亲戚
Ah01A09# 旁系亲属 直系亲属
Ah01A10# 亲家公 亲家母
Ah01B01= 眷属 亲属 家属 家眷 家小 老小 妻小 妻孥 骨肉 家人 家室 亲人 家口 妻儿老小 妻儿 妇婴
Ah01B02= 女眷 内眷
Ah01B03= 侨眷 侨属
Ah01B04# 烈属 军属 遗属 军眷 军烈 烈军属 警嫂
Ah02A01= 曾祖 曾祖父 老爷爷 太公 太爷 太翁 曾父
Ah02A02= 曾祖母 老奶奶 太婆
Ah02A03@ 祖父母
Ah02B01= 祖父 太爷 爷爷 爷 爹爹 老爹 公公 阿爹 太公 太翁 祖 老太公
Ah02B02@ 先祖
Ah02C01= 祖母 奶奶 婆婆 太婆 高祖母
Ah03A01@ 伯祖
Ah03A02@ 伯祖母
Ah03B01= 叔祖 叔公
Ah03B02= 叔祖母 叔婆
Ah03C01= 外祖父 外公 公公 老爷 姥爷
Ah03D01= 外祖母 外婆 姥姥 老娘 家母
Ah04A01= 父 父亲 爷 爹 大 翁 爸爸 老子 爹爹 老爹 阿爹 阿爸 椿 太公 大人 爸 生父 爹地 慈父
Ah04A02= 令尊 老太爷 老爷子
Ah04A03@ 家父
Ah04A04= 继父 后爹
Ah04A05= 养父 义父 干爸
Ah04A06= 先父 先人
Ah04A07@ 其父
Ah04B01= 母 母亲 慈母 阿妈 妈妈 妈 娘 萱 内亲 生母 娘亲 亲娘
Ah04B02= 令堂 老太太 太君
Ah04B03= 家母 老母 老娘
Ah04B04= 庶母 姨娘
Ah04B05= 继母 后母 后妈 后娘 晚娘
Ah04B06= 养母 义母 干娘 干妈
Ah04B07@ 先妣
Ah04B08@ 人母
Ah04C01= 父母 双亲 二老 爹娘 爹妈 堂上 上下 椿萱 大人 上人 老人 老人家 老亲 家长 考妣 父母亲 养父母 严父慈母
Ah04C02@ 干爷娘
Ah04C03= 保护者 保护人 衣食父母
Ah04D01= 父子 爷儿俩
Ah04D02# 父女 母女 母子
Ah05A01= 伯父 伯 大伯 大爷 伯伯 大
Ah05B01= 伯母 大妈 大娘 大大
Ah05C01= 叔父 叔 叔叔 季父 表叔 堂叔
Ah05D01= 叔母 婶 婶母 婶子 婶婶 婶娘
Ah06A01= 姑父 姑夫 姑丈
Ah06B01= 姑母 姑 姑姑 姑妈 姑娘 姑婆
Ah06B02@ 姑奶奶
Ah06B03# 三姑六婆 姑嫂
Ah06C01= 姨父 姨夫 姨丈
Ah06D01= 姨母 姨 姨儿 姨妈 阿姨 姨娘 姨婆
Ah06E01= 舅父 舅 舅舅 娘舅 小舅 表舅 大舅 郎舅
Ah06E02@ 舅爷
Ah06F01= 舅母 舅妈 妗子 妗
Ah06G01@ 两姨亲
Ah07A01= 公婆 姑舅
Ah07A02= 公公 公 翁 舅 嫜 老公公
Ah07A03= 婆婆 婆母 老婆婆 阿婆 姑 婆
Ah07B01@ 岳父母
Ah07B02= 岳父 岳丈 丈人 泰山 岳 老丈人 娘家人
Ah07B03= 岳母 丈母 丈母娘
Ah07C01@ 婆媳
Ah08A01= 夫 丈夫 爱人 男人 先生 女婿 老公 汉子 当家的 人夫 那口子
Ah08A02= 老伴 老头子 爷们 老伴儿
Ah08A03= 郎 郎君 官人 良人 夫子 夫君 夫婿 相公
Ah08A04@ 前夫
Ah08A05@ 未婚夫
Ah08B01= 妻 妻子 爱人 妻室 夫人 女人 老婆 太太 家 婆娘 婆姨 娘儿们 娘子 家里 老小 媳妇儿 老婆子 老伴 内 内助 妻妾 爱妻 贤内助
Ah08B02= 内人 拙荆 屋里
Ah08B03= 嫂夫人 尊夫人
Ah08B04= 发妻 元配 大老婆 正房 前妻 糟糠 糟糠之妻 原配
Ah08B05= 填房 继配 继室 续弦 后妻
Ah08B06@ 故人
Ah08B07= 妾 小 姬 小老婆 偏房 侧室 二房 姨太太 姨娘 陪房
Ah08B08@ 雌老虎
Ah08B09@ 未婚妻
Ah08C01= 夫妻 夫妇 两口子 小两口 老两口 家室 终身伴侣 伉俪
Ah08C02= 鸳鸯 鸾凤 比翼鸟 并蒂莲 连理
Ah08C03= 配偶 偶 逑
Ah08C04@ 结发夫妻
Ah08C05@ 佳偶
Ah08C06@ 怨偶
Ah09A01= 兄 兄长 哥 哥哥 阿哥 昆 老大哥 父兄
Ah09A02= 长兄 大哥
Ah09A03= 家兄 胞兄
Ah09B01= 弟 弟弟 兄弟 阿弟 棣
Ah09B02@ 令弟
Ah09B03@ 胞弟
Ah09B04= 堂哥哥 堂兄
Ah09B05= 师哥 师兄
Ah09B06@ 表哥
Ah09C01= 兄弟 弟兄 手足 哥儿 昆仲 雁行 棠棣 小兄弟 哥们 哥俩 哥们儿
Ah09C02= 同胞 亲兄弟 胞兄弟
Ah09C03@ 同母兄弟
Ah09C04@ 堂兄弟
Ah09C05= 表兄弟 老表
Ah09C06@ 堂弟
Ah09C07@ 表弟
Ah09C08@ 师弟
Ah09C09@ 姨表兄弟
Ah09D01@ 兄妹
Ah10A01= 姐 阿姐 姐姐 姊 老姐儿
Ah10A02@ 师姐
Ah10B01= 妹 阿妹 妹妹 妹子 娣 胞妹
Ah10B02@ 小妹
Ah10B03@ 师妹
Ah10C01= 姐妹 姊妹 姐儿
Ah10C02@ 亲姐妹
Ah10C03@ 堂姐妹
Ah10C04# 表姐妹 表姐 表妹
Ah10C05# 堂姐 堂妹
Ah10D01@ 姐弟
Ah11A01@ 妯娌
Ah11B01= 连襟 连袂 娅
Ah12A01= 嫂子 嫂 嫂嫂 大嫂 兄嫂
Ah12A02@ 表嫂
Ah12A03@ 军嫂
Ah12A04@ 纺嫂
Ah12B01= 弟妇 弟妹 婶 弟媳 婶婆
Ah12C01= 姐夫 姊夫
Ah12D01= 妹夫 妹婿
Ah13A01= 妻舅 舅子 舅舅
Ah13A02= 内兄 大舅子
Ah13A03= 内弟 小舅子 妇弟
Ah13B01= 姑 姑娘
Ah13B02= 大姑 大姑子
Ah13B03= 小姑 小姑子
Ah13C01@ 姨
Ah13C02= 大姨 大姨子
Ah13C03@ 小姨子
Ah13D01@ 小叔子
Ah14A01= 子 儿子 儿 男 崽 子嗣 小子 幼子
Ah14A02@ 庶子
Ah14A03= 养子 义子 螟蛉 干儿子
Ah14A04= 继子 继嗣
Ah14A05@ 爱子
Ah14A06= 小儿 犬子
Ah14A07= 令郎 少爷 相公 公子 哥儿
Ah14A08@ 亲子
Ah14A09# 大儿子 小儿子 老儿子 次子
Ah14B01= 女 女儿 闺女 姑娘 丫头 囡 幼女 姑娘家 丫 妮
Ah14B02@ 爱女
Ah14B03@ 小女
Ah14B04= 令爱 千金 女公子
Ah14B05= 养女 义女
Ah14B06# 长女 次女
Ah14C01= 子女 儿女 孩子 男女 骨血 囡 亲骨肉
Ah14C02= 心肝 宝贝 心肝宝贝 宠儿 命根子 掌上明珠 命根 宝贝儿
Ah14C03= 独子 独生子 独苗 单根独苗 独生女 独生子女
Ah14C04= 双胞胎 孪生子
Ah14C05= 混血儿 混血种 杂种
Ah14C06@ 三胞胎
Ah14C07# 私生子 野种
Ah15A01= 媳妇 媳 妇 儿媳 儿媳妇儿 子妇 儿媳妇 侄媳妇 孙媳妇
Ah15A02@ 童养媳
Ah15A03@ 洋媳妇
Ah15A04@ 小媳妇
Ah15A05@ 侄媳
Ah15B01= 女婿 婿 子婿 娇客 半子 坦 倩 甥 孙女婿 侄女婿
Ah15B02= 佳婿 乘龙快婿
Ah15B03= 赘婿 招女婿
Ah15B04= 姑老爷 姑爷
Ah15C01@ 翁婿
Ah16A01= 侄 侄子 表侄 内侄 侄儿
Ah16A02= 侄女 表侄女 内侄女
Ah16B01= 甥 外甥
Ah16B02= 甥女 外甥女
Ah16C01@ 叔侄
Ah17A01= 孙 孙子 嫡孙
Ah17A02@ 孙女
Ah17A03= 曾孙 重孙 祖孙
Ah17A04= 曾孙女 重孙女
Ah17A05= 外孙 外孙子
Ah17A06@ 外孙女
Ah17A07@ 爱孙
Ah17A08# 玄孙 侄孙 侄孙女 长孙 侄外孙
Ai01A01= 鼻祖 始祖 太祖 高祖
Ai01A02= 创始人 开山 祖师 祖师爷 元老 不祧之祖 开山祖师 老祖宗 奠基者 开拓者
Ai01B01= 前人 先驱 前驱 先驱者 先行者 先辈 前任 过来人
Ai01B02= 引进者 推荐者
Ai01B03@ 清人
Ai01C01= 今人 时人 世人 近人
Ai01C02= 一代人 当代人
Ai01C03@ 健在者
Ai01D01= 后人 后代 后来人 接班人 继承人 后任 后者 后世 传人 子孙后代 继任者 继承者 来人 膝下
Ai01E01@ 古人类
Ai01E02= 古人 原人 元人 原始人 猿人
Ai01E03# 直立人 龙门汤人 北京猿人 野人 智人 楼兰人 蓝田猿人 山顶洞人
Ai02A01= 祖宗 祖上 祖先 先人 先世 先祖 祖辈 上代
Ai02A02# 曾祖 高祖 远祖 列祖列宗
Ai02B01= 长辈 长上 长者 尊长 父老 老前辈 前辈 老一辈 先辈 老人 上人 老辈
Ai02B02= 父辈 大伯 伯父 老伯 世叔 叔叔 大叔 大爷 叔 爷 堂叔
Ai02B03= 大妈 大娘 大婶
Ai03A01@ 同辈
Ai03A02= 侪 同龄人
Ai03B01= 晚辈 晚 小辈 下辈 后辈 后生 后进 子弟 下一代 新一代
Ai03C01= 子孙 子嗣 儿孙 后代 后人 后嗣 后生 后裔 苗裔 裔 胄 后 裔 嗣 胄 胤 遗族 子代
Ai03C02@ 多子多孙
Ai03C03@ 子侄
Ai03D01= 受益者 受益人
Aj01A01= 朋友 友人 友好 友朋 交游 朋 友 哥儿们 宾朋
Aj01A02= 好友 挚友 执友 密友 契友 稔友 相知 知交 知音 知心人 至交 忘年交 莫逆之交 至好 至友
Aj01A03= 旧交 旧友 旧故 故旧 旧 故人 故交 老朋友 老友 老相识
Aj01A04= 新交 新知 初交
Aj01A05@ 故友
Aj01A06= 难友 患难之交
Aj01A07= 益友 诤友 良友 良师益友 师友
Aj01A08= 世交 世谊
Aj01A09= 诸亲好友 亲友 亲朋 亲朋好友 至亲好友 四座宾朋
Aj01A10@ 诗友
Aj01A11= 教友 校友
Aj01A12@ 熟人
Aj01A13# 点头之交 一面之交
Aj01A14# 畏友 酒肉朋友 狐朋狗友
Aj01A15# 战友 盟友 棋友 戏友 网友 文友 病友 读友 农友
Aj01A16@ 世叔
Aj01A17# 送礼者 受礼者
Aj01B01= 恩人 恩公 救星 重生父母
Aj01C01= 仇人 敌人 仇敌 仇家 寇仇 对头 冤家 仇 冤家对头 大敌
Aj01C02= 死敌 死对头 眼中钉 肉中刺
Aj01C03= 外敌 外寇
Aj01C04= 残敌 穷寇
Aj01C05= 夙仇 夙敌 夙世冤家 宿敌
Aj01C06@ 进攻方
Aj01C07# 公敌 政敌 论敌 情敌 假想敌 守敌 劲敌 顽敌 强敌 天敌 克星 敌伪
Aj01C08@ 敌我
Aj01D01= 对手 对方 敌手 敌 敌方 挑战者
Aj02A01= 自己人 知心人 贴心人 私人 近人 亲信 腹心
Aj02B01= 外人 局外人 陌生人 生人 路人 第三者 闲人 异己 旁观者 陌路
Aj02C01= 邻居 邻人 邻舍 邻里 近邻 街坊 左邻右舍 比邻 东邻西舍 老街旧邻 邻家 乡邻 远邻
Aj03A01= 一伙 一伙子 同伙 难兄难弟
Aj03A02= 一路货 狐群狗党 一丘之貉 同党
Aj03A03# 参加者 入会者 加入者 参会者 参赛者 参与者
Aj03B01= 同伴 同伙 伙伴 伴侣 伴 伴儿 侣 侣伴 俦 小伙伴
Aj03B02= 伙计 搭档 一行 一起 同路人 旅伴 老搭档
Aj03B03= 同道 同调 与共
Aj03B04= 合作者 合作方 合伙人
Aj03B05@ 非伙伴
Aj03B06@ 女伴
Aj03B07# 游伴 舞伴
Aj03B08# 本方 甲方
Aj03C01= 把兄弟 拜把兄弟 盟兄弟 八拜之交 同盟者
Aj04A01= 同学 同窗 同班 学友 校友 同桌 同校 同室
Aj04A02= 学长 学兄
Aj04A03@ 同年
Aj04A04# 老三届 应届
Aj04B01= 同事 同人 同仁
Aj04B02= 同僚 袍泽
Aj04B03@ 老同事
Aj05A01= 主人 主 东家 东道主 东 地主 主人公 东道 主人家 主子 庄家 东道国 主人翁
Aj05A02= 主妇 管家婆 内当家 女主人
Aj05A03= 寄主 宿主
Aj05B01= 客人 宾客 宾 客 来宾 来客
Aj05B02= 贵宾 上宾 佳宾 座上客 贵客 座上宾
Aj05B03= 男宾 男客
Aj05B04# 稀客 生客 远客 熟客 不速之客 八方来客
Aj05B05# 国宾 外宾
Aj05B06@ 内宾
Aj05C01= 宾主 主客
Aj05D01@ 受让人
Aj05D02@ 转让人
Aj05D03= 接受方 接受者
Aj06A01= 顾客 主顾 顾主 买主 客 客官 消费者
Aj06A02@ 申购者
Aj06A03= 购买者 买客 买者 买家 支付方
Aj06A04= 消费群 购买群 消费层
Aj06A05@ 常客
Aj06A06@ 客户群
Aj06A07@ 暴客
Aj06A08# 观众 听众
Aj06A09# 闻者 听者 观者 看客 围观者
Aj06A10# 读者 读者群 观众群
Aj06A11# 就餐者 购房者 购车者 投保者
Aj06A12# 房客 回头客 外客 陪客 茶客 舞客 舞员
Aj06A13# 散客 散户
Aj06A14# 租用者 使用者
Aj07A01= 成员 分子 积极分子 活动分子
Aj07A02= 人马 队伍 原班人马
Aj07A03= 党徒 党羽 徒子徒孙
Aj07A04= 私党 死党
Aj07A05@ 定员
Aj07A06@ 冗员
Aj07A07# 党员 团员 队员 党团员 共产党员 共青团员 少先队员 组员 老党员 地下党员 队友
Aj07A08# 社员 盟员 会员 委员 阁员 团员 国务委员 学部委员 议员 中央委员 主任委员
Aj07A09# 余党 爪子
Aj07A10# 工作队员 会议员
Aj07A11# 集训队员 登山队员 替补队员 考察队员
Aj07A12# 申请者 申请人
Aj08A01= 上级 上司 上面 上边 上头 长上 上峰 顶头上司
Aj08B01= 下级 部下 下属 属下 下面 下头 僚属 部属 属员 麾下 手底下 手下人 二把手
Aj08C01= 平级 同级
Aj08D01@ 上下级
Aj09A01= 助手 副手 副 助理 帮办 下手 帮手 羽翼 臂助 僚佐 左右手 膀臂 臂膀 股肱 助理员 帮厨
Aj09B01= 参谋 顾问 军师 师爷 智囊 谋士 策士 谋臣 总参 奇士谋臣
Aj09B02@ 狗头军师
Aj09C01= 靠山 后台 后盾 腰杆子 支柱 后台老板
Aj10A01= 师傅 师父 师
Aj10A02= 师母 师娘
Aj10B01= 徒弟 徒 学徒 练习生 徒子徒孙 徒孙
Aj11A01= 物主 主人 原主 本主儿 所有者 持有人 持有者
Aj11A02= 屋主 房东 房主 二房东 房产主
Aj11A03@ 失主
Aj11A04# 货主 户主 船主 车主 寨主 牧场主 鸡场主 厂主 窑主 牧主 矿主 种植园主 摊主
Aj11A05@ 电话拥有者
Aj11B01@ 收发人
Aj11B02= 收信人 接收者
Aj11B03= 寄卡人 寄信人 写信人
Aj12A01= 主持人 主席 召集人 主持者
Aj12A02# 主婚人 主考人 主编
Aj12B01= 司仪 打理 礼宾司
Aj12C01= 与会者 到会者
Aj12D01= 演讲者 讲话者 发言者
Aj12D02@ 主讲人
Aj13A01= 专人 专差 专使 专员
Aj13A02= 特派员 全权代表
Aj13A03= 钦差大臣 钦差
Aj13B01= 代表 代办 代理人 买办 委托人
Aj13B02= 代言人 发言人 喉舌
Aj13B03@ 总代理
Aj13B04# 人民代表 人大代表 党代表 军代表
Aj13B05@ 文化买办
Aj14A01= 见证人 见证 证人 活口 知情人 知情者
Aj14A02@ 目击者
Aj14B01= 保证人 保人 保 担保人 责任者 责任人 总负责人 行为人 责任人员 承担者 法人
Aj14C01= 中间人 中人 中
Aj14D01= 调解人 调人 和事老 调解者
Aj14D02@ 调停人
Aj14E01= 仲裁人 鉴定者 公证人 评判人 审判长 公证员
Aj14E02= 证婚 证婚人
Aj14E03@ 公家人
Aj14F01= 被告人 被上诉人 被告
Aj14F02@ 原告
Aj14G01= 举报者 举报人 报案人
Aj14H01@ 公诉人
Aj14H02@ 自诉人
Aj15A01= 介绍人 引线人
Aj15A02@ 托运人
Aj15B01= 媒人 媒介 媒婆 媒 介绍人 月老 月下老人 红娘 元煤
Aj15C01@ 傧相
Aj15C02= 男傧相 伴郎
Aj15C03= 伴娘 喜娘
Aj15D01= 中介 中介人
Aj15D02# 媒质 纽带
Aj16A01= 新郎 新人 新郎官
Aj16B01= 新娘 新娘子 新人 新媳妇儿 新妇 新人 新嫁娘 新娘
Aj16C01@ 新婚户
Aj17A01= 情人 情侣 冤家 对象 朋友 爱人 意中人 心上人 恋人 爱侣 有情人
Aj17A02= 男朋友 情郎 欢 男友
Aj17A03= 女朋友 女友
Aj17A04@ 牛郎织女
Aj17B01= 姘头 相好 外遇
Aj17B02= 情夫 姘夫 奸夫
Aj17B03= 情妇 姘妇 奸妇 二奶
Aj17C01= 王八 乌龟 绿头巾
Aj17D01@ 同性恋者
Ak01A01= 英雄 豪杰 英豪 英杰 好汉 烈士 志士 枭雄 英雄好汉 英雄豪杰 民族英雄 群雄 英雄汉 群英 无名英雄 雄鹰
Ak01A02= 有志者 有志之士
Ak01A03@ 女杰
Ak01A04# 武者 堂主
Ak01A05# 剑客 剑侠 大侠 独行侠
Ak01A06# 李逵 武松 李大钊 雷锋
Ak01B01= 硬汉 硬骨头 大丈夫 血性汉子 猛士 硬汉子 铁汉 勇敢者 勇者
Ak01C01= 烈士 先烈 国殇 英烈
Ak01C02@ 光荣户
Ak02A01= 勇士 武士 武夫 壮士 飞将军 好样儿的 斗士 大力士
Ak02B01= 侠客 侠 武侠 游侠 豪侠 豪客 义士
Ak02B02@ 牛仔
Ak02C01= 懦夫 胆小鬼 软骨头 孬种 窝囊废 脓包 孱头 狗熊
Ak02D01= 懒汉 懒虫
Ak03A01= 好人 明人 良民 良 令人 本分人 良善 善人 好心人 热心人
Ak03A02@ 正面人物
Ak03A03# 志愿者 献血者 贡献者
Ak03B01= 君子 高人 仁人君子 正人君子 仁人志士 志士仁人 谦谦君子 使君子
Ak03C01= 圣贤 圣 贤 圣人 贤人 哲人 高人 完人 贤达 贤能 贤哲 尧舜 先知 先知先觉 贤良 贤淑 医圣 哲 乡贤
Ak03C02= 先贤 先哲 前贤
Ak03C03= 元老 长者 泰山 泰斗 泰山北斗 鲁殿灵光
Ak03C04# 楚王 燕王 项羽
Ak03D01= 坏人 歹人 歹徒 败类 丑类 坏分子 坏东西 狗东西 癞皮狗 坏蛋 混蛋 禽兽 衣冠禽兽 无耻之徒 跳梁小丑 幺麽小丑 残渣余孽 谬种 破蛋 鼠类
Ak03D02= 小人 小丑 鼠辈 势利小人 阿谀奉承者
Ak03D03= 土棍 地痞 地头蛇 恶棍 光棍 无赖 恶人 乔
Ak03D04= 恶霸 霸 霸王 土皇帝 元凶
Ak03D05= 豪强 豪门
Ak03D06= 豺狼 魔鬼 魔王 蛇蝎 恶魔 虎狼 阎罗 阎王 活阎王 混世魔王 鬼魔 魔头
Ak03D07= 暴徒 强暴 凶残 不逞之徒 亡命之徒
Ak03D08@ 中山狼
Ak03D09= 奸邪 奸人 奸宄 佞人 奸佞 妖孽 祸水 害人虫 九尾狐 害群之马 牛鬼蛇神
Ak03D10= 野心家 奸雄 枭雄
Ak03D11= 独裁者 独夫 铁腕人物 铁腕
Ak03D12# 军阀 学阀 党阀 北洋军阀
Ak03D13# 党棍 学棍
Ak03D14# 渔霸 水霸 地霸 酒霸
Ak04A01= 老好人 好人 好好先生 菩萨 活菩萨 老实人
Ak04B01= 凶人 凶神 夜叉 饕餮 凶神恶煞
Ak04B02= 泼妇 悍妇 雌老虎 母夜叉
Ak05A01= 伪君子 假道学 笑面虎 两面派 变色龙 投机分子 乡愿
Ak05B01= 滑头 油子 老油子 老油条 老江湖 老狐狸 油嘴
Ak06A01= 吝啬鬼 守财奴 看财奴 小气鬼 铁公鸡 守财
Ak06B01= 市侩 势利眼 势利小人 市井之徒
Ak06B02= 造假者 弄虚作假者
Ak07A01= 孝子 孝子贤孙
Ak07B01= 逆子 孽障 业障 孽种 不肖子孙 不孝之子 不成人子
Ak08A01= 贞妇 烈女
Ak08B01= 荡妇 淫妇 破鞋
Ak08B02= 骚货 妖精 狐狸精 贱货 贱骨头
Ak09A01= 浪子 败家子 公子哥儿 花花公子 膏粱子弟 衙内 恶少 纨绔子弟
Ak09B01= 色鬼 色情狂 渔色之徒
Ak10A01= 老顽固 死顽固 顽固派 死硬派 死心眼儿 古董 骨董 老古董
Ak10B01= 学究 腐儒 迂夫子
Ak11A01= 急性子 直性子 直肠子
Ak11A02= 炮筒子 大炮 快嘴
Ak11A03@ 莽汉
Ak11B01= 慢郎中 慢性子 温吞水
Ak12A01= 话匣子 碎嘴子 贫嘴 长舌妇
Ak12A02@ 鼓吹者
Ak12A03@ 空谈者
Ak12B01= 应声虫 尾巴 传声筒 留声机
Ak12C01= 馋嘴 馋猫子 饕餮
Ak12D01= 夜游神 夜猫子
Ak12E01= 怪人 怪物 怪胎 奇人
Ak12F01@ 工作狂
Ak12F02@ 奋斗者
Ak12G01@ 倒蛋鬼
Ak12H01@ 嬉皮士
Ak12I01@ 活字典
Al01A01= 知识分子 文化人 读书人 先生 生员 书生 生 秀才 夫子 儒 儒生 士 士人 士大夫 文人 学子 斯文 文人墨客 文人 学士 莘莘学子 文人学士 一介书生 臭老九
Al01A02= 文弱书生 白面书生
Al01A03= 学者 鸿儒 大师 宗师 耆宿 名宿 老先生
Al01A04= 作家 大作家 文豪 文宗 文学家 笔杆子 大手笔 散文家 写家 女作家 作家群
Al01A05= 诗人 词人 骚人 骚客
Al01A06= 诗仙 诗圣 词宗
Al01A07= 画家 画师
Al01A08@ 艺术家
Al01A09@ 书法家
Al01A10= 寒士 措大
Al01A11= 书呆子 老夫子 迂夫子 书痴
Al01A12= 文痞 文侩
Al01A13@ 脑力劳动者
Al01A14# 雅人 文抄公 雅士 硕儒
Al01A15# 杜甫 李白 屈原
Al01A16# 徐悲鸿 巴金 郭沫若 鲁迅 李大钊 周波
Al01B01= 文盲 睁眼瞎子 半文盲 睁眼瞎 科盲
Al01B02= 大老粗 土包子
Al01B03@ 法盲
Al02A01= 内行 行家 熟手 里手 好手 老手 把势 把式 通 一把手 快手 老资格 熟练工 内行人 行家里手
Al02B01= 专家 专门家 家 师 学者 大方 大家 土专家 学家
Al02B02= 识途老马 宿将 三朝元老 老将
Al02B03# 革命家 政治家 思想家 理论家 军事家 教育家 科学家 艺术家 文学家 音乐家 歌唱家 舞蹈家 法学家 观察家 航海家 化学家 活动家 经济学家 美术家 企业家 物理学家 戏剧家 演奏家 探险家 医学家 语言学家 杂家 哲学家 篆刻家 散文家 社会学家 史学家 收藏家 数学家 美食家 批评家 漫画家 人口学家 战略家 社会科学家 地质学家 动物学家 文艺家 生态学家 历史学家 天文学家 生物学家 核物理学家 精神分析学家 建筑学家 地理学家 实业家 鸟类学家 股评家 古人类学家 小说家 人类学家 评论家 昆虫学家 生理学家 鉴赏家 遗传学家 统计学家 考古学家 金融家 集邮家 美学家 小提琴家 汉学家 农学家 儿童文学家 古生物学家 神学家 教育学家 心理学家 刑法学家 经销家 摄影家 表演艺术家 分析家 市场分析家 外交家 慈善家 空想家 雕刻家 投资家 炒家 剧作家 曲作者 翻译家 散文家 电影家 钢琴家 演唱家 小提琴家 文艺家 词作家 编导家 雕塑家 儿童文学家 指挥家 国画家 版画家 花鸟画家 书画家 油画家 名画家 改革家 谋略家 史论家 政论家 作曲家 冒险家 出版家 银行家
Al02B04# 研究员 副研究员 研制者 研究者 发现者
Al02B05# 发明人 发明者 发明家 创造者
Al02B06# 设计家 设计师 设计员
Al02B07# 制造家 制造者 制作者
Al02B08# 高级工程师 工程师 助理工程师 技师 技术员 总工程师 技士 总工 机械师 农机手 轮机手 机械手 机师 高工
Al02B09# 经济师 药剂师 拳师 拳王 营养师 麻醉师 估价师 修脚师 针灸师 舞美师 拍卖师 精算师 药师 气功师 灯光师 工艺师 策略师 审计师 美术师 建筑师 工艺美术师 农艺师
Al02B10# 棋王 棋圣 草圣 棋后
Al02B11@ 历史学者
Al02B12# 收藏者 藏书家
Al02B13# 神炮手 神枪手
Al02B14@ 理论工作者
Al02B15@ 伯乐
Al02C01= 骨干 基干 桢干 主角 支柱 顶梁柱 擎天柱 台柱子 柱石 栋梁 中坚 中流砥柱 台柱 栋梁之材
Al02D01= 外行 门外汉
Al02D02= 生手 新手
Al02E01@ 说客
Al03A01= 俊杰 豪杰 杰 英 豪 英豪 俊秀 英华 女杰
Al03A02= 人杰 翘楚 魁首 状元 高明 尖儿 尖子 超人 骥 大器 佼佼者
Al03B01= 人才 材 材料 佳人 才子 奇才 天才 英才 千里驹 麟凤龟龙 精英 人材 一表人材 栋梁材 有用之才 怪杰 才女 才子佳人 贤才 彦
Al03B02@ 闺秀
Al03B03= 女将 巾帼英雄 女强人
Al03B04= 能手 能人 干将 健将 王牌 权威 好手 上手 国手 高手 妙手 圣手 硬手 一把手 大师 宗师 大王 宗匠 巨匠 能工巧匠 名手 棋手
Al03B05= 多面手 通才 全才 通人 百事通 万事通
Al03B06= 新秀 后起之秀 龙驹 新锐
Al03B07= 庸中佼佼 强者 强手 强手如林
Al03B08= 高才生 七步之才 巨子
Al03B09# 歌王 球王
Al03B10# 地灵人杰 德才兼备
Al03B11@ 拳手
Al04A01= 聪明人 智者 智囊 智多星 诸葛亮
Al04A02= 明眼人 有识之士 明白人 亮眼人
Al04A03@ 神童
Al04A04= 机灵鬼 猴儿 鬼灵精
Al04A05# 前茅 优胜者
Al04B01= 笨伯 笨蛋 笨人 笨货 笨家伙 愚人 蠢人 蠢货 蠢材 木头 木头人儿 愚氓 木头人
Al04B02= 饭桶 草包 废物 乏货 朽木 二五眼 窝囊废 酒囊饭袋 行尸走肉 朽木粪土
Al04B03= 傻子 傻瓜 二百五 呆子 低能儿 痴子 白痴 傻帽 二愣子
Al04C01= 庸人 庸才 凡人 凡庸 中人 平流 阿斗 匹夫 井底之蛙 凡夫俗子 等闲之辈 庸者 井底蛙
Al04C02= 绣花枕头 纸老虎
Al04C03= 半瓶醋 二百五 半吊子 二把刀 万金油
Al04C04= 浑蛋 混蛋 妄人
Al04C05= 活宝 宝贝 宝贝儿
Al04C06= 糊涂虫 糊涂蛋 马大哈
Al04C07@ 乌合之众
Al05A01= 模范 标兵 表率 榜样 师表 轨范 楷范 英模 典型 丰碑
Al05A02= 劳模 劳动模范
Al05A03@ 铁人
Al05A04# 冠军 亚军 季军 殿军 冠亚军
Al05A05@ 擂主
Al05A06# 排头兵 三好生
Al05B01= 先锋 急先锋 开路先锋 先行官 先遣 先行者
Al05B02# 旗手 红旗手 持旗人 持旗者 突击手 弄潮儿
Al05B03@ 创新者
Al05C01= 功臣 元勋
Al05C02@ 有功者
Al05D01@ 偶像
Al06A01= 爱好者 发烧友
Al06A02# 棋迷 球迷 戏迷 影迷 牌迷 舞迷 歌迷 财迷 鸟迷 书迷 京剧迷 乐迷 邮迷 扑克迷 网络迷 票友
Al06A03# 追星族 崇拜者
Am01A01= 教徒 信徒 善男信女 信教者
Am01A02# 圣徒 新教徒 异教徒 清教徒
Am01A03# 八大山人 忠清南道人 犹大 三藏
Am01A04@ 神职人员
Am01B01@ 佛教徒
Am01B02= 佛 菩萨 祖师 罗汉 金刚 十八罗汉
Am01B03= 沙门 僧尼 僧人 出家人
Am01B04= 僧徒 僧侣 僧 和尚 沙弥 道人 行者 头陀 高僧
Am01B05= 尼姑 尼 姑子 师姑 仙姑 比丘尼
Am01B06@ 长老
Am01B07= 禅师 活佛 大师傅 大师 师父 法师 上人
Am01B08= 住持 方丈 当家的
Am01B09@ 香火
Am01B10@ 苦行僧
Am01B11# 施主 檀越 居士 信士 信女 香客 护法
Am01C01@ 转世灵童
Am02A01= 道教徒 道徒
Am02A02= 道士 法师 方士 老道 妖道
Am02A03@ 道姑
Am02A04# 神人 真人 祖师
Am02B01@ 喇嘛教徒
Am02B02# 活佛 喇嘛 达赖喇嘛 达赖
Am03A01= 伊斯兰教徒 回教徒 穆斯林
Am03A02@ 阿訇
Am03B01= 天主教徒 天主
Am03B02= 枢机主教 红衣主教
Am03B03= 神甫 神父
Am03B04# 教皇 大主教 主教 修士 修女 教主
Am03C01= 耶稣教徒 基督徒
Am03C02# 牧师 传教士 教士 使徒
Am03D01@ 神
Am03D02# 大力神 守护神
Am03D03@ 阿波罗
An01A01= 反动派 反革命 反 反动分子 造反派 批斗者
An01A02= 反派 反面人物
An01A03= 匪帮 匪徒 白匪 黑社会
An01A04= 刽子手 屠夫
An01A05= 战争贩子 战争狂人 战犯
An01A06@ 宪兵队
An01A07@ 军统
An01A08@ 阴谋家
An01B01= 叛徒 内奸 奸 逆 叛逆 叛乱者
An01B02@ 贰臣
An01B03= 卖国贼 国贼 民贼
An01B04= 奸贼 贼 蟊贼 独夫民贼
An01B05= 儿皇帝 傀儡
An01B06# 叛兵 逃兵
An02A01= 罪犯 罪人 人犯 囚 囚犯 囚徒 犯人 阶下囚 监犯 释放者
An02A02= 死囚 死刑犯
An02A03= 凶犯 凶手 杀人犯 刺客 杀手
An02A04= 主犯 要犯 首恶 正凶 元凶 罪魁 主谋 主使 祸首 罪魁祸首 首犯 主凶
An02A05= 从犯 同谋犯 同案犯
An02A06= 逃犯 在逃犯 漏网之鱼
An02A07= 教唆犯 教唆者
An02A08= 窝主 窝家
An02A09= 嫌疑人 疑凶
An02A10@ 女犯
An02A11# 战犯 政治犯 刑事犯 诈骗犯 走私犯 强奸犯 纵火犯 抢劫犯 贪污犯 未遂犯 未决犯 已决犯 在押犯 嫌疑犯 现行犯 惯犯 案犯 盗犯 劫机犯 劳改犯 流窜犯 少年犯 通缉犯 嫌犯 疑犯 重犯 假释犯 服刑犯 盗窃犯 积犯 作案人 玩忽职守者
An02A12# 破坏者 污染者
An02A13# 肇事人 肇事者
An02A14# 不法之徒 犯罪分子 违法者 以身试法者 涉案人员 违犯者
An02A15# 违纪者 违章者
An03A01= 强盗 盗 寇 匪 匪徒 土匪 强人 盗匪 匪盗 盗贼 豪客 异客 歹人 胡匪 胡子 盗寇
An03A02= 匪首 盗魁 草头王
An03A03= 草寇 绿林 绿林好汉 草莽英雄
An03A04@ 帝国主义者
An03A05= 殖民者 殖民主义者
An03A06# 绑匪 股匪 惯匪 劫持犯 绑架者 偷车贼 车匪 悍匪 叛匪 逃税者 盗车人 偷猎者
An03A07# 马贼 海盗 江洋大盗
An03A08# 外寇 海寇 倭寇 流寇 日寇 日伪 敌寇
An03A09# 袭击者 劫机者
An03A10# 残匪 车匪路霸
An03B01= 窃贼 贼 小偷 瘪三 梁上君子 鸡鸣狗盗 破门而入者
An03B02= 惯贼 惯窃 惯偷 惯盗
An03B03@ 扒手
An03B04= 盗码者 黑客
An03B05= 剽窃者 盗卖者
An03B06= 侠盗 家贼 飞贼 工贼
An03C01= 入侵者 征服者 侵略者
An04A01= 流氓 痞子 泼皮 光棍 无赖 兵痞 无赖汉 渣子 刺儿头 盲流 刺头
An04A02= 二流子 浪子 浪人 阿飞
An04A03@ 失足者
An04B01= 骗子 拐子 骗子手 诈骗者 奸徒
An04B02@ 假冒者
An04B03# 江湖骗子 人贩子 偷香盗玉者 负心人
An04B04@ 西门豹
An04C01= 投机商 奸商 黄牛党 黄牛 投机者 经济人
An04D01= 毒贩 毒枭 贩毒者
An05A01= 走狗 狗腿子 腿子 鹰犬 奴才 帮凶 打手 走卒 爪牙 喽罗 汉奸 洋奴 鹰爪
An06A01= 赌徒 赌棍 赌鬼 赌客
An06B01= 酒徒 大户 酒鬼 醉鬼 醉汉
An06C01= 烟鬼 隐君子 烟民 吸烟者
An06C02@ 吸毒者
An06D01@ 始作俑者
An07A01= 妓女 妓 娼 娼妓 娼妇 婊子 花魁 神女
An07A02@ 窑姐儿
An07A03= 艺妓 摇钱树
An07A04= 暗娼 私娼 野鸡
An07A05@ 三陪
An07A06# 花瓶 交际花 舞女
An07B01= 男妓 相公
An07C01= 鸨母 鸨儿 掌班 妈妈 老鸨
An07D01= 龟奴 乌龟 相帮 王八
An07E01= 嫖客 孤老 客人 客
Ba01A01= 物 实物 东西 家伙 玩意儿 钱物 玩意
Ba01A02= 物质 质 素
Ba01A03@ 万物
Ba01A04@ 身外之物
Ba01A05@ 遗传物质
Ba01A06@ 博物
Ba01A07= 占有物 专有物
Ba01A08@ 非法所得
Ba01A09@ 何物
Ba01A10@ 芸芸众生
Ba01A11@ 外包装
Ba01A12# 电介质 电解质 溶质 腐殖质 介质 原生质 石灰质 有机质
Ba01A13# 光密媒质 光疏媒质
Ba01A14# 社会存在物 自然存在物
Ba01A15# 有机物 无机物
Ba01A16# 生成物 生产物 地物 原物 土物 沉淀物 参照物 静物 障碍物 赘物 重物 致癌物 示踪物 对立物 易爆物 颗粒物 山神灵物 吉祥物 囊中物 书物 混合物 猎物 标识物 包装物 人财物 抵
gitextract_90z__jgc/
├── .gitignore
├── .travis.yml
├── LICENSE
├── README.md
├── pom.xml
└── src/
└── main/
├── java/
│ └── cn/
│ └── codepub/
│ ├── algorithms/
│ │ ├── arrays/
│ │ │ └── PrintArray.java
│ │ ├── commons/
│ │ │ ├── ConversionOfNumberSystems.java
│ │ │ ├── MajorityNumber.java
│ │ │ ├── MaximumProduct.java
│ │ │ └── TopK.java
│ │ ├── graph/
│ │ │ ├── Dijkstra.java
│ │ │ ├── DirectedGraphByAdjacencyList.java
│ │ │ ├── DirectedGraphByAdjacencyMatrix.java
│ │ │ ├── FloydWarshall.java
│ │ │ ├── Kruskal.java
│ │ │ ├── Prim.java
│ │ │ ├── UndirectedGraphByAdjacencyList.java
│ │ │ ├── UndirectedGraphByAdjacencyMatrix.java
│ │ │ └── utils/
│ │ │ └── UnionFindSet.java
│ │ ├── matrix/
│ │ │ └── Matrix.java
│ │ ├── multithread/
│ │ │ └── ThreadSynchronization.java
│ │ ├── queue/
│ │ │ └── PriorityApp.java
│ │ ├── similarity/
│ │ │ └── cilin/
│ │ │ └── WordSimilarity.java
│ │ ├── sorting/
│ │ │ ├── BubbleSort.java
│ │ │ ├── InsertSort.java
│ │ │ ├── QuickSort.java
│ │ │ ├── SelectionSort.java
│ │ │ └── ShellSort.java
│ │ ├── spelling/
│ │ │ └── ChineseToSpelling.java
│ │ ├── stack/
│ │ │ ├── BracketsApp.java
│ │ │ ├── CheckStackSequence.java
│ │ │ ├── InfixApp.java
│ │ │ ├── MinStack.java
│ │ │ └── PostfixApp.java
│ │ ├── strings/
│ │ │ ├── BinarySearch.java
│ │ │ ├── Combination.java
│ │ │ ├── JaccardSimilarityCoefficient.java
│ │ │ ├── LCS.java
│ │ │ ├── LCS2.java
│ │ │ ├── LCS3.java
│ │ │ ├── LevenshteinDistance.java
│ │ │ ├── LongestDecreasingSubSequence.java
│ │ │ ├── Manacher.java
│ │ │ ├── PatternStringMatch.java
│ │ │ ├── Permutation.java
│ │ │ ├── ReverseString.java
│ │ │ └── StringSort.java
│ │ ├── trees/
│ │ │ ├── DepthFirstTraversal.java
│ │ │ ├── GetPathsBySum.java
│ │ │ ├── LevelTraverseBinaryTree.java
│ │ │ ├── TraverseBinaryTree.java
│ │ │ └── VerifySequenceOfBST.java
│ │ └── utils/
│ │ ├── StackX.java
│ │ └── Tree.java
│ └── patterns/
│ ├── core/
│ │ ├── DeepClone.java
│ │ └── Singleton.java
│ └── proxy/
│ ├── CGLibProxyHandler.java
│ ├── CountImpl.java
│ ├── JDKProxyHandler.java
│ └── StaticProxyHandler.java
└── resources/
├── cilin.txt
└── log4j2.xml
SYMBOL INDEX (289 symbols across 55 files)
FILE: src/main/java/cn/codepub/algorithms/arrays/PrintArray.java
class PrintArray (line 21) | public class PrintArray {
method main (line 25) | public static void main(String[] args) {
method moveRight (line 36) | private static void moveRight(int curRow, int curCol, int rows, int co...
method moveDown (line 50) | private static void moveDown(int curRow, int curCol, int rows, int col...
method moveLeft (line 64) | private static void moveLeft(int curRow, int curCol, int rows, int col...
method moveUp (line 79) | private static void moveUp(int curRow, int curCol, int rows, int cols,...
FILE: src/main/java/cn/codepub/algorithms/commons/ConversionOfNumberSystems.java
class ConversionOfNumberSystems (line 21) | public class ConversionOfNumberSystems {
method conversion (line 29) | public static String conversion(int number, int base) {
method baseString (line 65) | public static String baseString(int num, int base) {
method test (line 75) | @Test
FILE: src/main/java/cn/codepub/algorithms/commons/MajorityNumber.java
class MajorityNumber (line 20) | public class MajorityNumber {
method main (line 21) | public static void main(String[] args) {
method majorityNumber (line 30) | public int majorityNumber(ArrayList<Integer> nums) {
FILE: src/main/java/cn/codepub/algorithms/commons/MaximumProduct.java
class MaximumProduct (line 22) | public class MaximumProduct {
method getMaximumProduct (line 30) | public static long getMaximumProduct(long[] arrs) {
method test (line 48) | @Test
FILE: src/main/java/cn/codepub/algorithms/commons/TopK.java
class TopK (line 25) | public class TopK {
method getTopK (line 36) | public static boolean getTopK(int n, int k) {
method printTopK (line 71) | public static void printTopK(Queue queue) {
method test (line 79) | @Test
FILE: src/main/java/cn/codepub/algorithms/graph/Dijkstra.java
class Dijkstra (line 22) | public class Dijkstra {
class Vertex (line 28) | class Vertex {
method Vertex (line 32) | public Vertex(char name) {
class Edge (line 38) | class Edge {
method Edge (line 43) | public Edge(int value) {
method create (line 48) | @org.junit.Test
method getShortestPath (line 95) | public static void getShortestPath(Vertex[] vertexes) {
method getNo (line 178) | private static int getNo(Vertex[] vertexes, char name) {
FILE: src/main/java/cn/codepub/algorithms/graph/DirectedGraphByAdjacencyList.java
class DirectedGraphByAdjacencyList (line 22) | public class DirectedGraphByAdjacencyList {
method main (line 23) | public static void main(String[] args) {
method breadthFirstSearch (line 30) | private void breadthFirstSearch() {
method depthFirstSearch (line 59) | public void depthFirstSearch() {
method depthFirstSearch (line 69) | private void depthFirstSearch(boolean[] visited, int i) {
class Edge (line 83) | private class Edge {
class Vertex (line 89) | private class Vertex {
method createGraph (line 100) | public void createGraph() {
method getPosition (line 167) | private int getPosition(String v1) {
FILE: src/main/java/cn/codepub/algorithms/graph/DirectedGraphByAdjacencyMatrix.java
class DirectedGraphByAdjacencyMatrix (line 23) | public class DirectedGraphByAdjacencyMatrix {
method main (line 27) | public static void main(String[] args) {
method breadthFirstSearch (line 34) | public void breadthFirstSearch() {
method getNextVertex (line 68) | private int getNextVertex(int row, int col) {
method createGraph (line 80) | public void createGraph() {
method depthFirstSearch (line 124) | public void depthFirstSearch() {
method depthFirstSearch (line 143) | private void depthFirstSearch(boolean[] visited, int i) {
method getPosition (line 162) | public int getPosition(String s) {
FILE: src/main/java/cn/codepub/algorithms/graph/FloydWarshall.java
class FloydWarshall (line 21) | public class FloydWarshall {
class Vertex (line 27) | class Vertex {
method Vertex (line 31) | public Vertex(char name) {
class Edge (line 37) | class Edge {
method Edge (line 42) | public Edge(int value) {
method create (line 47) | @org.junit.Test
method getShortestPathByDp (line 86) | public static void getShortestPathByDp(Vertex[] vertexes) {
method getNo (line 134) | private static int getNo(Vertex[] vertexes, char name) {
method constructShortestPath (line 150) | public static String constructShortestPath(int start, int end) {
FILE: src/main/java/cn/codepub/algorithms/graph/Kruskal.java
class Kruskal (line 27) | public class Kruskal {
class Vertex (line 43) | private static class Vertex {
method Vertex (line 46) | public Vertex(char name) {
method toString (line 50) | @Override
class Edge (line 56) | private static class Edge {
method Edge (line 61) | public Edge(Vertex a, Vertex b, int val) {
method toString (line 67) | @Override
method addEdge (line 80) | public static void addEdge(Vertex a, Vertex b, int val) {
method minimumSpanningTree (line 85) | public static void minimumSpanningTree() {
method getVertexNo (line 105) | private static int getVertexNo(List<Vertex> vertexList, char name) {
method create (line 114) | @Test
FILE: src/main/java/cn/codepub/algorithms/graph/Prim.java
class Prim (line 23) | public class Prim {
class Vertex (line 24) | private static class Vertex {
method Vertex (line 27) | public Vertex(char name) {
method Vertex (line 31) | public Vertex() {
method toString (line 35) | @Override
class Edge (line 41) | private static class Edge {
method Edge (line 46) | public Edge(Vertex start, Vertex end, int value) {
method addEdge (line 57) | public static void addEdge(Vertex a, Vertex b, int val) {
method minimumSpanningTree (line 66) | public static void minimumSpanningTree() {
method containVertex (line 97) | private static boolean containVertex(char name) {
method create (line 106) | @Test
FILE: src/main/java/cn/codepub/algorithms/graph/UndirectedGraphByAdjacencyList.java
class UndirectedGraphByAdjacencyList (line 22) | public class UndirectedGraphByAdjacencyList {
method main (line 23) | public static void main(String[] args) {
method breadthFirstSearch (line 48) | private void breadthFirstSearch() {
method depthFirstSearch (line 77) | public void depthFirstSearch() {
method depthFirstSearch (line 87) | private void depthFirstSearch(boolean[] visited, int i) {
class Edge (line 101) | private class Edge {
class Vertex (line 107) | private class Vertex {
method createGraph (line 118) | public void createGraph() {
method getPosition (line 201) | private int getPosition(String v1) {
FILE: src/main/java/cn/codepub/algorithms/graph/UndirectedGraphByAdjacencyMatrix.java
class UndirectedGraphByAdjacencyMatrix (line 24) | public class UndirectedGraphByAdjacencyMatrix {
method main (line 28) | public static void main(String[] args) {
method breadthFirstSearch (line 45) | public void breadthFirstSearch() {
method createGraph (line 75) | public void createGraph() {
method depthFirstSearch (line 120) | public void depthFirstSearch() {
method depthFirstSearch (line 139) | private void depthFirstSearch(boolean[] visited, int i) {
method getNextVertex (line 159) | private int getNextVertex(int row, int col) {
method getPosition (line 174) | public int getPosition(String s) {
FILE: src/main/java/cn/codepub/algorithms/graph/utils/UnionFindSet.java
class UnionFindSet (line 18) | public class UnionFindSet {
method UnionFindSet (line 23) | public UnionFindSet() {
method UnionFindSet (line 27) | public UnionFindSet(int size) {
method init (line 35) | private void init() {
method makeSet (line 44) | public void makeSet() {
method findSet (line 57) | public int findSet(int x) {
method union (line 71) | public void union(int x, int y) {
FILE: src/main/java/cn/codepub/algorithms/matrix/Matrix.java
class Matrix (line 18) | public class Matrix {
method main (line 23) | public static void main(String[] args) {
FILE: src/main/java/cn/codepub/algorithms/multithread/ThreadSynchronization.java
class ThreadSynchronization (line 20) | public class ThreadSynchronization extends Thread {
method ThreadSynchronization (line 28) | public ThreadSynchronization(AtomicInteger synObj, String name, int fl...
method run (line 34) | @Override
method main (line 57) | public static void main(String[] args) {
FILE: src/main/java/cn/codepub/algorithms/queue/PriorityApp.java
class PriorityApp (line 20) | public class PriorityApp {
method main (line 21) | public static void main(String[] args) {
class PriorityQ (line 34) | class PriorityQ {
method PriorityQ (line 39) | public PriorityQ(int s) {
method insert (line 45) | public void insert(long item) {
method remove (line 64) | public long remove() {
method peekMin (line 68) | public long peekMin() {
method isEmpty (line 72) | public boolean isEmpty() {
method isFull (line 76) | public boolean isFull() {
FILE: src/main/java/cn/codepub/algorithms/similarity/cilin/WordSimilarity.java
class WordSimilarity (line 34) | @Log4j2
method readCiLin (line 70) | private static void readCiLin() {
method getSimilarity (line 119) | public static double getSimilarity(String word1, String word2) {
method isIndependent (line 189) | private boolean isIndependent(String source) {
method getEncode (line 212) | protected static ArrayList<String> getEncode(String word) {
method getN (line 223) | protected static int getN(String encodeHead) {
method getCount (line 239) | protected static int getCount(String encodeHead, int end) {
method getK (line 261) | protected static int getK(String encode1, String encode2) {
method getCommonStr (line 298) | protected static String getCommonStr(String encode1, String encode2) {
method testGetN (line 318) | @Test
method testGetK (line 325) | @Test
method testGetCommonStr (line 331) | @Test
method testGetSimilarity (line 337) | @Test
method testGetSimilarity2 (line 362) | @Test
FILE: src/main/java/cn/codepub/algorithms/sorting/BubbleSort.java
class BubbleSort (line 22) | public class BubbleSort {
method bubbleSort (line 23) | public void bubbleSort(int[] nums) {
method swap (line 33) | public void swap(int[] nums, int one, int two) {
method test (line 39) | @Test
FILE: src/main/java/cn/codepub/algorithms/sorting/InsertSort.java
class InsertSort (line 20) | public class InsertSort {
method main (line 21) | public static void main(String[] args) {
method swap (line 35) | private static void swap(int[] nums, int first, int second) {
FILE: src/main/java/cn/codepub/algorithms/sorting/QuickSort.java
class QuickSort (line 20) | public class QuickSort {
method main (line 21) | public static void main(String[] args) {
method quickSort (line 27) | public void quickSort(int nums[], int start, int end) {
method swap (line 54) | private void swap(int nums[], int left, int right) {
FILE: src/main/java/cn/codepub/algorithms/sorting/SelectionSort.java
class SelectionSort (line 22) | public class SelectionSort {
method selectionSort (line 23) | public void selectionSort(int[] nums) {
method swap (line 36) | public void swap(int[] nums, int one, int two) {
method test (line 42) | @Test
FILE: src/main/java/cn/codepub/algorithms/sorting/ShellSort.java
class ShellSort (line 20) | public class ShellSort {
method main (line 21) | public static void main(String[] args) {
method swap (line 43) | private static void swap(int[] nums, int first, int second) {
FILE: src/main/java/cn/codepub/algorithms/spelling/ChineseToSpelling.java
class ChineseToSpelling (line 21) | public class ChineseToSpelling {
method convertChineseToSpelling (line 25) | public static String convertChineseToSpelling(String chinese, Spelling...
type SpellingFormat (line 47) | enum SpellingFormat {
FILE: src/main/java/cn/codepub/algorithms/stack/BracketsApp.java
class BracketsApp (line 25) | public class BracketsApp {
method main (line 26) | public static void main(String[] args) throws IOException {
method getString (line 40) | public static String getString() throws IOException {
class BracketChecker (line 48) | class BracketChecker {
method BracketChecker (line 51) | public BracketChecker(String in) {
method check (line 55) | public void check() {
FILE: src/main/java/cn/codepub/algorithms/stack/CheckStackSequence.java
class CheckStackSequence (line 29) | public class CheckStackSequence {
method main (line 30) | public static void main(String[] args) {
method check (line 56) | public static boolean check(int[] nums1, int[] nums2) {
FILE: src/main/java/cn/codepub/algorithms/stack/InfixApp.java
class InfixApp (line 27) | public class InfixApp {
method main (line 28) | public static void main(String[] args) throws IOException {
method getString (line 44) | public static String getString() throws IOException {
class InToPost (line 54) | class InToPost {
method InToPost (line 59) | public InToPost(String in) {
method doTrans (line 65) | public String doTrans() {
method gotOper (line 97) | public void gotOper(char opThis, int prec1) {
method gotParen (line 121) | public void gotParen(char ch) {
FILE: src/main/java/cn/codepub/algorithms/stack/MinStack.java
class MinStack (line 21) | public class MinStack {
method main (line 22) | public static void main(String[] args) {
FILE: src/main/java/cn/codepub/algorithms/stack/PostfixApp.java
class PostfixApp (line 31) | public class PostfixApp {
method main (line 32) | public static void main(String[] args) throws Exception {
method getString (line 48) | public static String getString() throws Exception {
class ParsePost (line 57) | class ParsePost {
method ParsePost (line 61) | public ParsePost(String s) {
method doParse (line 65) | public int doParse() {
FILE: src/main/java/cn/codepub/algorithms/strings/BinarySearch.java
class BinarySearch (line 19) | public class BinarySearch {
method recursionBinarySearch (line 30) | private static int recursionBinarySearch(int[] nums, int start, int en...
method nonRecursionBinarySearch (line 55) | private static int nonRecursionBinarySearch(int[] nums, int key) {
method main (line 73) | public static void main(String[] args) {
FILE: src/main/java/cn/codepub/algorithms/strings/Combination.java
class Combination (line 18) | public class Combination {
method main (line 22) | public static void main(String[] args) {
method combination (line 39) | public static void combination(char[] strs, int start, int number) {
method combination (line 63) | public static void combination() {
FILE: src/main/java/cn/codepub/algorithms/strings/JaccardSimilarityCoefficient.java
class JaccardSimilarityCoefficient (line 26) | public class JaccardSimilarityCoefficient {
method getJSC (line 27) | public double getJSC(String str1, String str2) {
method calcBySets (line 57) | public static double calcBySets(String s0, String s1) {
FILE: src/main/java/cn/codepub/algorithms/strings/LCS.java
class LCS (line 20) | public class LCS {
method lcsBase (line 21) | public static String lcsBase(String inputX, String inputY) {
method getMax (line 36) | private static String getMax(String x, String y) {
method test (line 57) | @Test
FILE: src/main/java/cn/codepub/algorithms/strings/LCS2.java
class LCS2 (line 20) | public class LCS2 {
method getComLen (line 21) | private static Integer getComLen(String firstStr, String secondStr) {
method lcsBase (line 35) | private static String lcsBase(String inputX, String inputY) {
method test (line 51) | @Test
FILE: src/main/java/cn/codepub/algorithms/strings/LCS3.java
class LCS3 (line 20) | public class LCS3 {
method lcsDp (line 21) | public static String lcsDp(String inputX, String inputY) {
method test (line 59) | @Test
FILE: src/main/java/cn/codepub/algorithms/strings/LevenshteinDistance.java
class LevenshteinDistance (line 20) | public class LevenshteinDistance {
method leDistance (line 21) | public static int leDistance(String inputX, String inputY) {
method test (line 44) | @Test
FILE: src/main/java/cn/codepub/algorithms/strings/LongestDecreasingSubSequence.java
class LongestDecreasingSubSequence (line 14) | public class LongestDecreasingSubSequence {
method main (line 15) | public static void main(String[] args) {
method getLongestDecreaseSubSequence (line 29) | public List<Integer> getLongestDecreaseSubSequence(int[] nums) {
method getLongestIncreaseSubSequence (line 69) | public List<Integer> getLongestIncreaseSubSequence(int[] nums) {
FILE: src/main/java/cn/codepub/algorithms/strings/Manacher.java
class Manacher (line 26) | public class Manacher {
method main (line 27) | public static void main(String[] args) {
method getMaxPalindrome (line 38) | private int getMaxPalindrome(String str) {
FILE: src/main/java/cn/codepub/algorithms/strings/PatternStringMatch.java
class PatternStringMatch (line 18) | public class PatternStringMatch {
method main (line 19) | public static void main(String[] args) {
method search (line 32) | private static int search(String text, String pat) {
FILE: src/main/java/cn/codepub/algorithms/strings/Permutation.java
class Permutation (line 39) | public class Permutation {
method main (line 42) | public static void main(String[] args) {
method permutation (line 47) | public static void permutation(char[] strs, int start, int end) {
method swap (line 61) | private static void swap(char[] chars, int first, int second) {
FILE: src/main/java/cn/codepub/algorithms/strings/ReverseString.java
class ReverseString (line 23) | public class ReverseString {
method ReverseString (line 27) | public ReverseString(String in) {
method doRev (line 31) | public String doRev() {
method getString (line 45) | public static String getString() throws Exception {
method main (line 52) | public static void main(String[] args) throws Exception {
FILE: src/main/java/cn/codepub/algorithms/strings/StringSort.java
class StringSort (line 21) | public class StringSort {
method main (line 23) | public static void main(String[] args) {
method bubbleSort (line 34) | public static void bubbleSort(String[] strs) {
method compare (line 55) | private static int compare(String s1, String s2) {
FILE: src/main/java/cn/codepub/algorithms/trees/DepthFirstTraversal.java
class DepthFirstTraversal (line 22) | public class DepthFirstTraversal {
method main (line 25) | public static void main(String[] args) {
method dfs (line 46) | public static void dfs(Tree root) {
FILE: src/main/java/cn/codepub/algorithms/trees/GetPathsBySum.java
class GetPathsBySum (line 26) | public class GetPathsBySum {
method main (line 30) | public static void main(String[] args) {
method dfs (line 60) | public static void dfs(Tree root, List<Tree> path) {
FILE: src/main/java/cn/codepub/algorithms/trees/LevelTraverseBinaryTree.java
class LevelTraverseBinaryTree (line 24) | public class LevelTraverseBinaryTree {
method main (line 25) | public static void main(String[] args) {
method levelTraverse (line 43) | public static void levelTraverse(Tree root, Queue<Tree> queue) {
FILE: src/main/java/cn/codepub/algorithms/trees/TraverseBinaryTree.java
class TraverseBinaryTree (line 20) | public class TraverseBinaryTree {
method main (line 21) | public static void main(String[] args) {
method preOrder (line 43) | public static void preOrder(Tree root) {
method inOrder (line 56) | public static void inOrder(Tree root) {
method postOrder (line 69) | public static void postOrder(Tree root) {
FILE: src/main/java/cn/codepub/algorithms/trees/VerifySequenceOfBST.java
class VerifySequenceOfBST (line 22) | public class VerifySequenceOfBST {
method main (line 23) | public static void main(String[] args) {
method verify (line 32) | public static boolean verify(int[] sequences) {
FILE: src/main/java/cn/codepub/algorithms/utils/StackX.java
class StackX (line 18) | public class StackX<T> {
method StackX (line 23) | public StackX() {
method StackX (line 27) | public StackX(int s) {
method push (line 33) | public void push(T j) {
method pop (line 37) | public T pop() {
method peek (line 41) | public T peek() {
method isEmpty (line 45) | public boolean isEmpty() {
method size (line 49) | public int size() {
method peekN (line 53) | public T peekN(int n) {
method displayStack (line 57) | public void displayStack(String s) {
FILE: src/main/java/cn/codepub/algorithms/utils/Tree.java
class Tree (line 18) | public class Tree {
method Tree (line 24) | public Tree() {
method Tree (line 28) | public Tree(int value) {
method toString (line 32) | @Override
FILE: src/main/java/cn/codepub/patterns/core/DeepClone.java
class DeepClone (line 21) | public class DeepClone {
method main (line 22) | public static void main(String[] args) {
class MyPerson (line 42) | class MyPerson implements Cloneable, Serializable {
method MyPerson (line 47) | public MyPerson(String name, int age) {
method MyPerson (line 52) | public MyPerson(String name, int age, MyPerson son) {
method deepClone (line 57) | public Object deepClone() throws IOException, ClassNotFoundException {
method clone (line 68) | @Override
FILE: src/main/java/cn/codepub/patterns/core/Singleton.java
class Singleton (line 21) | public class Singleton {
method Singleton (line 22) | private Singleton() {
method getInstance (line 28) | public static Singleton getInstance() {
method main (line 39) | public static void main(String[] args) {
FILE: src/main/java/cn/codepub/patterns/proxy/CGLibProxyHandler.java
class CGLibProxyHandler (line 26) | public class CGLibProxyHandler implements MethodInterceptor {
method getInstance (line 34) | public Object getInstance(Object tar) {
method intercept (line 55) | @Override
method testCGLibProxy (line 64) | @org.junit.Test
FILE: src/main/java/cn/codepub/patterns/proxy/CountImpl.java
type Count (line 6) | interface Count {
method queryCount (line 8) | void queryCount();
method updateCount (line 11) | void updateCount();
class CountImpl (line 14) | public class CountImpl implements Count {
method queryCount (line 15) | @Override
method updateCount (line 20) | @Override
FILE: src/main/java/cn/codepub/patterns/proxy/JDKProxyHandler.java
class JDKProxyHandler (line 26) | public class JDKProxyHandler implements InvocationHandler {
method JDKProxyHandler (line 29) | public JDKProxyHandler() {
method JDKProxyHandler (line 33) | public JDKProxyHandler(Object tar) {
method bind (line 37) | public Object bind(Object tar) {
method invoke (line 42) | @Override
method testDynamicProxy (line 52) | public static void testDynamicProxy() {
method main (line 59) | public static void main(String[] args) {
FILE: src/main/java/cn/codepub/patterns/proxy/StaticProxyHandler.java
class StaticProxyHandler (line 18) | public class StaticProxyHandler implements Count {
method StaticProxyHandler (line 22) | public StaticProxyHandler() {
method StaticProxyHandler (line 27) | public StaticProxyHandler(Count count) {
method queryCount (line 31) | @Override
method updateCount (line 39) | @Override
method main (line 47) | public static void main(String[] args) {
method testStaticProxy (line 51) | public static void testStaticProxy() {
Condensed preview — 62 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (1,135K chars).
[
{
"path": ".gitignore",
"chars": 31,
"preview": "/.idea/\nAlgorithms.iml\n/target/"
},
{
"path": ".travis.yml",
"chars": 36,
"preview": "language: java\r\njdk:\r\n - oraclejdk8"
},
{
"path": "LICENSE",
"chars": 11547,
"preview": "\r\n\r\n Apache License\r\n Version 2.0, January 2004\r\n "
},
{
"path": "README.md",
"chars": 7095,
"preview": "Algorithms [](https://travis-ci.org"
},
{
"path": "pom.xml",
"chars": 2985,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<project xmlns=\"http://maven.apache.org/POM/4.0.0\"\n xmlns:xsi=\"http://www"
},
{
"path": "src/main/java/cn/codepub/algorithms/arrays/PrintArray.java",
"chars": 2755,
"preview": "package cn.codepub.algorithms.arrays;\r\n\r\nimport java.util.ArrayList;\r\nimport java.util.List;\r\n\r\n/**\r\n * <p>\r\n * Created "
},
{
"path": "src/main/java/cn/codepub/algorithms/commons/ConversionOfNumberSystems.java",
"chars": 1956,
"preview": "package cn.codepub.algorithms.commons;\r\n\r\nimport org.junit.Assert;\r\nimport org.junit.Test;\r\n\r\n/**\r\n * <p>\r\n * Created wi"
},
{
"path": "src/main/java/cn/codepub/algorithms/commons/MajorityNumber.java",
"chars": 1659,
"preview": "package cn.codepub.algorithms.commons;\r\n\r\nimport java.util.ArrayList;\r\n\r\n/**\r\n * <p>\r\n * Created with IntelliJ IDEA. 201"
},
{
"path": "src/main/java/cn/codepub/algorithms/commons/MaximumProduct.java",
"chars": 1376,
"preview": "package cn.codepub.algorithms.commons;\r\n\r\nimport org.junit.Test;\r\n\r\n/**\r\n * <p>\r\n * Created with IntelliJ IDEA. 15/12/17"
},
{
"path": "src/main/java/cn/codepub/algorithms/commons/TopK.java",
"chars": 2103,
"preview": "package cn.codepub.algorithms.commons;\r\n\r\nimport org.junit.Test;\r\n\r\nimport java.util.Comparator;\r\nimport java.util.Prior"
},
{
"path": "src/main/java/cn/codepub/algorithms/graph/Dijkstra.java",
"chars": 5402,
"preview": "package cn.codepub.algorithms.graph;\r\n\r\nimport java.util.ArrayDeque;\r\nimport java.util.Arrays;\r\nimport java.util.Queue;\r"
},
{
"path": "src/main/java/cn/codepub/algorithms/graph/DirectedGraphByAdjacencyList.java",
"chars": 5588,
"preview": "package cn.codepub.algorithms.graph;\r\n\r\nimport java.util.ArrayDeque;\r\nimport java.util.Queue;\r\nimport java.util.Scanner;"
},
{
"path": "src/main/java/cn/codepub/algorithms/graph/DirectedGraphByAdjacencyMatrix.java",
"chars": 4963,
"preview": "package cn.codepub.algorithms.graph;\r\n\r\nimport java.util.ArrayDeque;\r\nimport java.util.Arrays;\r\nimport java.util.Queue;\r"
},
{
"path": "src/main/java/cn/codepub/algorithms/graph/FloydWarshall.java",
"chars": 4589,
"preview": "package cn.codepub.algorithms.graph;\r\n\r\nimport java.util.Arrays;\r\n\r\n/**\r\n * <p>\r\n * Created with IntelliJ IDEA. 2015/12/"
},
{
"path": "src/main/java/cn/codepub/algorithms/graph/Kruskal.java",
"chars": 3876,
"preview": "package cn.codepub.algorithms.graph;\r\n\r\nimport cn.codepub.algorithms.graph.utils.UnionFindSet;\r\nimport org.junit.Test;\r\n"
},
{
"path": "src/main/java/cn/codepub/algorithms/graph/Prim.java",
"chars": 3534,
"preview": "package cn.codepub.algorithms.graph;\r\n\r\nimport org.junit.Test;\r\n\r\nimport java.util.ArrayList;\r\nimport java.util.List;\r\n\r"
},
{
"path": "src/main/java/cn/codepub/algorithms/graph/UndirectedGraphByAdjacencyList.java",
"chars": 6820,
"preview": "package cn.codepub.algorithms.graph;\r\n\r\nimport java.util.ArrayDeque;\r\nimport java.util.Queue;\r\nimport java.util.Scanner;"
},
{
"path": "src/main/java/cn/codepub/algorithms/graph/UndirectedGraphByAdjacencyMatrix.java",
"chars": 5326,
"preview": "package cn.codepub.algorithms.graph;\r\n\r\nimport java.util.ArrayDeque;\r\nimport java.util.Arrays;\r\nimport java.util.Queue;\r"
},
{
"path": "src/main/java/cn/codepub/algorithms/graph/utils/UnionFindSet.java",
"chars": 1835,
"preview": "package cn.codepub.algorithms.graph.utils;\r\n\r\n/**\r\n * <p>\r\n * Created with IntelliJ IDEA. 15/12/16 16:34\r\n * </p>\r\n * <p"
},
{
"path": "src/main/java/cn/codepub/algorithms/matrix/Matrix.java",
"chars": 956,
"preview": "package cn.codepub.algorithms.matrix;\r\n\r\n/**\r\n * <p>\r\n * Created with IntelliJ IDEA. 2015/10/10 20:37\r\n * </p>\r\n * <p>\r\n"
},
{
"path": "src/main/java/cn/codepub/algorithms/multithread/ThreadSynchronization.java",
"chars": 1919,
"preview": "package cn.codepub.algorithms.multithread;\r\n\r\nimport java.util.concurrent.atomic.AtomicInteger;\r\n\r\n/**\r\n * <p>\r\n * Creat"
},
{
"path": "src/main/java/cn/codepub/algorithms/queue/PriorityApp.java",
"chars": 1836,
"preview": "package cn.codepub.algorithms.queue;\r\n\r\n/**\r\n * <p>\r\n * Created with IntelliJ IDEA. 2016/1/8 19:57\r\n * </p>\r\n * <p>\r\n * "
},
{
"path": "src/main/java/cn/codepub/algorithms/similarity/cilin/WordSimilarity.java",
"chars": 12451,
"preview": "package cn.codepub.algorithms.similarity.cilin;\r\n\r\nimport com.google.common.base.Preconditions;\r\nimport lombok.extern.lo"
},
{
"path": "src/main/java/cn/codepub/algorithms/sorting/BubbleSort.java",
"chars": 955,
"preview": "package cn.codepub.algorithms.sorting;\r\n\r\nimport org.junit.Test;\r\n\r\nimport java.util.Arrays;\r\n\r\n/**\r\n * <p>\r\n * Created "
},
{
"path": "src/main/java/cn/codepub/algorithms/sorting/InsertSort.java",
"chars": 914,
"preview": "package cn.codepub.algorithms.sorting;\r\n\r\nimport java.util.Arrays;\r\n\r\n/**\r\n * <p>\r\n * Created with IntelliJ IDEA. 2015/1"
},
{
"path": "src/main/java/cn/codepub/algorithms/sorting/QuickSort.java",
"chars": 1411,
"preview": "package cn.codepub.algorithms.sorting;\r\n\r\nimport java.util.Arrays;\r\n\r\n/**\r\n * <p>\r\n * Created with IntelliJ IDEA. 2015/1"
},
{
"path": "src/main/java/cn/codepub/algorithms/sorting/SelectionSort.java",
"chars": 1043,
"preview": "package cn.codepub.algorithms.sorting;\r\n\r\nimport org.junit.Test;\r\n\r\nimport java.util.Arrays;\r\n\r\n/**\r\n * <p>\r\n * Created "
},
{
"path": "src/main/java/cn/codepub/algorithms/sorting/ShellSort.java",
"chars": 1225,
"preview": "package cn.codepub.algorithms.sorting;\r\n\r\nimport java.util.Arrays;\r\n\r\n/**\r\n * <p>\r\n * Created with IntelliJ IDEA. 2015/1"
},
{
"path": "src/main/java/cn/codepub/algorithms/spelling/ChineseToSpelling.java",
"chars": 1459,
"preview": "package cn.codepub.algorithms.spelling;\r\n\r\nimport com.github.stuxuhai.jpinyin.PinyinFormat;\r\nimport com.github.stuxuhai."
},
{
"path": "src/main/java/cn/codepub/algorithms/stack/BracketsApp.java",
"chars": 2528,
"preview": "package cn.codepub.algorithms.stack;\r\n\r\nimport cn.codepub.algorithms.utils.StackX;\r\n\r\nimport java.io.BufferedReader;\r\nim"
},
{
"path": "src/main/java/cn/codepub/algorithms/stack/CheckStackSequence.java",
"chars": 2475,
"preview": "package cn.codepub.algorithms.stack;\r\n\r\nimport java.util.Stack;\r\n\r\n/**\r\n * <p>\r\n * Created with IntelliJ IDEA. 2015/10/2"
},
{
"path": "src/main/java/cn/codepub/algorithms/stack/InfixApp.java",
"chars": 3487,
"preview": "package cn.codepub.algorithms.stack;\r\n\r\nimport cn.codepub.algorithms.utils.StackX;\r\n\r\nimport java.io.BufferedReader;\r\nim"
},
{
"path": "src/main/java/cn/codepub/algorithms/stack/MinStack.java",
"chars": 1014,
"preview": "package cn.codepub.algorithms.stack;\r\n\r\nimport java.util.Stack;\r\n\r\n/**\r\n * <p>\r\n * Created with IntelliJ IDEA. 2015/10/2"
},
{
"path": "src/main/java/cn/codepub/algorithms/stack/PostfixApp.java",
"chars": 2738,
"preview": "package cn.codepub.algorithms.stack;\r\n\r\n\r\nimport cn.codepub.algorithms.utils.StackX;\r\n\r\nimport java.io.BufferedReader;\r\n"
},
{
"path": "src/main/java/cn/codepub/algorithms/strings/BinarySearch.java",
"chars": 2614,
"preview": "package cn.codepub.algorithms.strings;\r\n\r\n/**\r\n * <p>\r\n * Created with IntelliJ IDEA. 2015/10/15 17:15\r\n * </p>\r\n * <p>\r"
},
{
"path": "src/main/java/cn/codepub/algorithms/strings/Combination.java",
"chars": 2612,
"preview": "package cn.codepub.algorithms.strings;\r\n\r\n/**\r\n * <p>\r\n * Created with IntelliJ IDEA. 2015/10/30 21:43\r\n * </p>\r\n * <p>\r"
},
{
"path": "src/main/java/cn/codepub/algorithms/strings/JaccardSimilarityCoefficient.java",
"chars": 2251,
"preview": "package cn.codepub.algorithms.strings;\r\n\r\nimport com.google.common.base.Preconditions;\r\nimport com.google.common.collect"
},
{
"path": "src/main/java/cn/codepub/algorithms/strings/LCS.java",
"chars": 2013,
"preview": "package cn.codepub.algorithms.strings;\r\n\r\nimport org.apache.commons.lang3.StringUtils;\r\nimport org.junit.Test;\r\n\r\n/**\r\n "
},
{
"path": "src/main/java/cn/codepub/algorithms/strings/LCS2.java",
"chars": 1592,
"preview": "package cn.codepub.algorithms.strings;\r\n\r\nimport org.apache.commons.lang3.StringUtils;\r\nimport org.junit.Test;\r\n\r\n/**\r\n "
},
{
"path": "src/main/java/cn/codepub/algorithms/strings/LCS3.java",
"chars": 1649,
"preview": "package cn.codepub.algorithms.strings;\r\n\r\nimport org.apache.commons.lang3.StringUtils;\r\nimport org.junit.Test;\r\n\r\n/**\r\n "
},
{
"path": "src/main/java/cn/codepub/algorithms/strings/LevenshteinDistance.java",
"chars": 1304,
"preview": "package cn.codepub.algorithms.strings;\r\n\r\nimport org.apache.commons.lang3.StringUtils;\r\nimport org.junit.Test;\r\n\r\n/**\r\n "
},
{
"path": "src/main/java/cn/codepub/algorithms/strings/LongestDecreasingSubSequence.java",
"chars": 3547,
"preview": "package cn.codepub.algorithms.strings;\r\n\r\nimport java.util.ArrayList;\r\nimport java.util.List;\r\n\r\n/**\r\n * 求解思路(以递减子序列为例):"
},
{
"path": "src/main/java/cn/codepub/algorithms/strings/Manacher.java",
"chars": 2390,
"preview": "package cn.codepub.algorithms.strings;\r\n\r\nimport org.apache.commons.lang3.StringUtils;\r\n\r\nimport java.util.Arrays;\r\n\r\n/*"
},
{
"path": "src/main/java/cn/codepub/algorithms/strings/PatternStringMatch.java",
"chars": 1399,
"preview": "package cn.codepub.algorithms.strings;\r\n\r\n/**\r\n * <p>\r\n * Created with IntelliJ IDEA. 2015/10/22 15:17\r\n * </p>\r\n * <p>\r"
},
{
"path": "src/main/java/cn/codepub/algorithms/strings/Permutation.java",
"chars": 1721,
"preview": "package cn.codepub.algorithms.strings;\r\n\r\n/**\r\n * <p>\r\n * Created with IntelliJ IDEA. 2015/10/30 19:37\r\n * </p>\r\n * <p>\r"
},
{
"path": "src/main/java/cn/codepub/algorithms/strings/ReverseString.java",
"chars": 1752,
"preview": "package cn.codepub.algorithms.strings;\r\n\r\nimport cn.codepub.algorithms.utils.StackX;\r\n\r\nimport java.io.BufferedReader;\r\n"
},
{
"path": "src/main/java/cn/codepub/algorithms/strings/StringSort.java",
"chars": 2015,
"preview": "package cn.codepub.algorithms.strings;\r\n\r\n\r\nimport java.util.Arrays;\r\n\r\n/**\r\n * <p>\r\n * Created with IntelliJ IDEA. 2015"
},
{
"path": "src/main/java/cn/codepub/algorithms/trees/DepthFirstTraversal.java",
"chars": 1550,
"preview": "package cn.codepub.algorithms.trees;\r\n\r\nimport cn.codepub.algorithms.utils.Tree;\r\n\r\nimport java.util.Stack;\r\n\r\n/**\r\n * <"
},
{
"path": "src/main/java/cn/codepub/algorithms/trees/GetPathsBySum.java",
"chars": 2276,
"preview": "package cn.codepub.algorithms.trees;\r\n\r\nimport cn.codepub.algorithms.utils.Tree;\r\n\r\nimport java.util.ArrayList;\r\nimport "
},
{
"path": "src/main/java/cn/codepub/algorithms/trees/LevelTraverseBinaryTree.java",
"chars": 1475,
"preview": "package cn.codepub.algorithms.trees;\r\n\r\nimport cn.codepub.algorithms.utils.Tree;\r\n\r\nimport java.util.ArrayDeque;\r\nimport"
},
{
"path": "src/main/java/cn/codepub/algorithms/trees/TraverseBinaryTree.java",
"chars": 1951,
"preview": "package cn.codepub.algorithms.trees;\r\n\r\nimport cn.codepub.algorithms.utils.Tree;\r\n\r\n/**\r\n * <p>\r\n * Created with Intelli"
},
{
"path": "src/main/java/cn/codepub/algorithms/trees/VerifySequenceOfBST.java",
"chars": 1687,
"preview": "package cn.codepub.algorithms.trees;\r\n\r\nimport java.util.Arrays;\r\n\r\n/**\r\n * <p>\r\n * Created with IntelliJ IDEA. 2015/10/"
},
{
"path": "src/main/java/cn/codepub/algorithms/utils/StackX.java",
"chars": 1207,
"preview": "package cn.codepub.algorithms.utils;\r\n\r\n/**\r\n * <p>\r\n * Created with IntelliJ IDEA. 2016/1/8 19:18\r\n * </p>\r\n * <p>\r\n * "
},
{
"path": "src/main/java/cn/codepub/algorithms/utils/Tree.java",
"chars": 600,
"preview": "package cn.codepub.algorithms.utils;\r\n\r\n/**\r\n * <p>\r\n * Created with IntelliJ IDEA. 2015/10/30 14:50\r\n * </p>\r\n * <p>\r\n "
},
{
"path": "src/main/java/cn/codepub/patterns/core/DeepClone.java",
"chars": 2138,
"preview": "package cn.codepub.patterns.core;\r\n\r\nimport java.io.*;\r\nimport java.util.Hashtable;\r\n\r\n/**\r\n * <p>\r\n * Created with Inte"
},
{
"path": "src/main/java/cn/codepub/patterns/core/Singleton.java",
"chars": 1114,
"preview": "package cn.codepub.patterns.core;\r\n\r\nimport java.util.HashSet;\r\nimport java.util.Set;\r\n\r\n/**\r\n * <p>\r\n * Created with In"
},
{
"path": "src/main/java/cn/codepub/patterns/proxy/CGLibProxyHandler.java",
"chars": 1949,
"preview": "package cn.codepub.patterns.proxy;\r\n\r\nimport net.sf.cglib.proxy.Enhancer;\r\nimport net.sf.cglib.proxy.MethodInterceptor;\r"
},
{
"path": "src/main/java/cn/codepub/patterns/proxy/CountImpl.java",
"chars": 462,
"preview": "package cn.codepub.patterns.proxy;\r\n\r\n/**\r\n * 静态代理、JDK动态代理、CGLib代理的辅助类\r\n */\r\ninterface Count {\r\n //定义查询账户方法\r\n void"
},
{
"path": "src/main/java/cn/codepub/patterns/proxy/JDKProxyHandler.java",
"chars": 1648,
"preview": "package cn.codepub.patterns.proxy;\r\n\r\nimport java.lang.reflect.InvocationHandler;\r\nimport java.lang.reflect.Method;\r\nimp"
},
{
"path": "src/main/java/cn/codepub/patterns/proxy/StaticProxyHandler.java",
"chars": 1353,
"preview": "package cn.codepub.patterns.proxy;\r\n\r\n/**\r\n * <p>\r\n * Created with IntelliJ IDEA. 2015/10/21 19:33\r\n * </p>\r\n * <p>\r\n * "
},
{
"path": "src/main/resources/cilin.txt",
"chars": 482329,
"preview": "Aa01A01= 人 士 人物 人士 人氏 人选\r\nAa01A02= 人类 生人 全人类\r\nAa01A03= 人手 人员 人口 人丁 口 食指\r\nAa01A04= 劳力 劳动力 工作者\r\nAa01A05= 匹夫 个人\r\nAa01A06= 家"
},
{
"path": "src/main/resources/log4j2.xml",
"chars": 1173,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n\r\n<Configuration status=\"OFF\">\r\n <Appenders>\r\n <RollingFile name=\"outE"
}
]
About this extraction
This page contains the full source code of the shijiebei2009/Algorithms GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 62 files (624.7 KB), approximately 433.2k tokens, and a symbol index with 289 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.