Rename the common modules in Java, C++ and C.
This commit is contained in:
parent
c6eecfd0dc
commit
145975b335
@ -5,7 +5,6 @@ set(CMAKE_C_STANDARD 11)
|
|||||||
|
|
||||||
include_directories(./include)
|
include_directories(./include)
|
||||||
|
|
||||||
add_subdirectory(include)
|
|
||||||
add_subdirectory(chapter_computational_complexity)
|
add_subdirectory(chapter_computational_complexity)
|
||||||
add_subdirectory(chapter_array_and_linkedlist)
|
add_subdirectory(chapter_array_and_linkedlist)
|
||||||
add_subdirectory(chapter_stack_and_queue)
|
add_subdirectory(chapter_stack_and_queue)
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: MolDuM (moldum@163.com)
|
* Author: MolDuM (moldum@163.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.h"
|
#include "../utils/common.h"
|
||||||
|
|
||||||
/* 随机返回一个数组元素 */
|
/* 随机返回一个数组元素 */
|
||||||
int randomAccess(int *nums, int size) {
|
int randomAccess(int *nums, int size) {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Zero (glj0@outlook.com)
|
* Author: Zero (glj0@outlook.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.h"
|
#include "../utils/common.h"
|
||||||
|
|
||||||
/* 在链表的节点 n0 之后插入节点 P */
|
/* 在链表的节点 n0 之后插入节点 P */
|
||||||
void insert(ListNode *n0, ListNode *P) {
|
void insert(ListNode *n0, ListNode *P) {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Zero (glj0@outlook.com)
|
* Author: Zero (glj0@outlook.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.h"
|
#include "../utils/common.h"
|
||||||
|
|
||||||
/* 列表类简易实现 */
|
/* 列表类简易实现 */
|
||||||
struct myList {
|
struct myList {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Guanngxu (446678850@qq.com)
|
* Author: Guanngxu (446678850@qq.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.h"
|
#include "../utils/common.h"
|
||||||
|
|
||||||
/* 二分查找(双闭区间) */
|
/* 二分查找(双闭区间) */
|
||||||
int binarySearch(int *nums, int len, int target) {
|
int binarySearch(int *nums, int len, int target) {
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
* Created Time: 2023-04-15
|
* Created Time: 2023-04-15
|
||||||
* Author: Gonglja (glj0@outlook.com)
|
* Author: Gonglja (glj0@outlook.com)
|
||||||
*/
|
*/
|
||||||
#include "../include/include.h"
|
#include "../utils/common.h"
|
||||||
|
|
||||||
/* 函数 */
|
/* 函数 */
|
||||||
int func() {
|
int func() {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: sjinzh (sjinzh@gmail.com)
|
* Author: sjinzh (sjinzh@gmail.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.h"
|
#include "../utils/common.h"
|
||||||
|
|
||||||
/* 常数阶 */
|
/* 常数阶 */
|
||||||
int constant(int n) {
|
int constant(int n) {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: sjinzh (sjinzh@gmail.com)
|
* Author: sjinzh (sjinzh@gmail.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.h"
|
#include "../utils/common.h"
|
||||||
|
|
||||||
/* 生成一个数组,元素为 { 1, 2, ..., n },顺序被打乱 */
|
/* 生成一个数组,元素为 { 1, 2, ..., n },顺序被打乱 */
|
||||||
int *randomNumbers(int n) {
|
int *randomNumbers(int n) {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Guanngxu (446678850@qq.com)
|
* Author: Guanngxu (446678850@qq.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.h"
|
#include "../utils/common.h"
|
||||||
|
|
||||||
/* 哈希表默认数组大小 */
|
/* 哈希表默认数组大小 */
|
||||||
# define HASH_MAP_DEFAULT_SIZE 100
|
# define HASH_MAP_DEFAULT_SIZE 100
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Reanon (793584285@qq.com)
|
* Author: Reanon (793584285@qq.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.h"
|
#include "../utils/common.h"
|
||||||
|
|
||||||
#define MAX_SIZE 5000
|
#define MAX_SIZE 5000
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Gonglja (glj0@outlook.com)
|
* Author: Gonglja (glj0@outlook.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.h"
|
#include "../utils/common.h"
|
||||||
|
|
||||||
/* 哈希表 */
|
/* 哈希表 */
|
||||||
struct hashTable {
|
struct hashTable {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Reanon (793584285@qq.com)
|
* Author: Reanon (793584285@qq.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.h"
|
#include "../utils/common.h"
|
||||||
|
|
||||||
/* 方法一:暴力枚举 */
|
/* 方法一:暴力枚举 */
|
||||||
int *twoSumBruteForce(int *nums, int numsSize, int target, int *returnSize) {
|
int *twoSumBruteForce(int *nums, int numsSize, int target, int *returnSize) {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Guanngxu (446678850@qq.com)
|
* Author: Guanngxu (446678850@qq.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.h"
|
#include "../utils/common.h"
|
||||||
|
|
||||||
/* 线性查找(数组) */
|
/* 线性查找(数组) */
|
||||||
int linearSearchArray(int *nums, int len, int target) {
|
int linearSearchArray(int *nums, int len, int target) {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Listening (https://github.com/L-Super)
|
* Author: Listening (https://github.com/L-Super)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.h"
|
#include "../utils/common.h"
|
||||||
|
|
||||||
/* 冒泡排序 */
|
/* 冒泡排序 */
|
||||||
void bubbleSort(int nums[], int size) {
|
void bubbleSort(int nums[], int size) {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Reanon (793584285@qq.com), Guanngxu (446678850@qq.com)
|
* Author: Reanon (793584285@qq.com), Guanngxu (446678850@qq.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.h"
|
#include "../utils/common.h"
|
||||||
|
|
||||||
/* 计数排序 */
|
/* 计数排序 */
|
||||||
// 简单实现,无法用于排序对象
|
// 简单实现,无法用于排序对象
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Listening (https://github.com/L-Super)
|
* Author: Listening (https://github.com/L-Super)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.h"
|
#include "../utils/common.h"
|
||||||
|
|
||||||
/* 插入排序 */
|
/* 插入排序 */
|
||||||
void insertionSort(int nums[], int size) {
|
void insertionSort(int nums[], int size) {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Guanngxu (446678850@qq.com)
|
* Author: Guanngxu (446678850@qq.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.h"
|
#include "../utils/common.h"
|
||||||
|
|
||||||
/* 合并左子数组和右子数组 */
|
/* 合并左子数组和右子数组 */
|
||||||
// 左子数组区间 [left, mid]
|
// 左子数组区间 [left, mid]
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Reanon (793584285@qq.com)
|
* Author: Reanon (793584285@qq.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.h"
|
#include "../utils/common.h"
|
||||||
|
|
||||||
/* 元素交换 */
|
/* 元素交换 */
|
||||||
void swap(int nums[], int i, int j) {
|
void swap(int nums[], int i, int j) {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Reanon (793584285@qq.com)
|
* Author: Reanon (793584285@qq.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.h"
|
#include "../utils/common.h"
|
||||||
|
|
||||||
/* 获取元素 num 的第 k 位,其中 exp = 10^(k-1) */
|
/* 获取元素 num 的第 k 位,其中 exp = 10^(k-1) */
|
||||||
int digit(int num, int exp) {
|
int digit(int num, int exp) {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Gonglja (glj0@outlook.com)
|
* Author: Gonglja (glj0@outlook.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.h"
|
#include "../utils/common.h"
|
||||||
|
|
||||||
/* 基于环形数组实现的双向队列 */
|
/* 基于环形数组实现的双向队列 */
|
||||||
struct arrayDeque {
|
struct arrayDeque {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Zero (glj0@outlook.com)
|
* Author: Zero (glj0@outlook.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.h"
|
#include "../utils/common.h"
|
||||||
|
|
||||||
/* 基于环形数组实现的队列 */
|
/* 基于环形数组实现的队列 */
|
||||||
struct arrayQueue {
|
struct arrayQueue {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Zero (glj0@outlook.com)
|
* Author: Zero (glj0@outlook.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.h"
|
#include "../utils/common.h"
|
||||||
|
|
||||||
#define MAX_SIZE 5000
|
#define MAX_SIZE 5000
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Gonglja (glj0@outlook.com)
|
* Author: Gonglja (glj0@outlook.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.h"
|
#include "../utils/common.h"
|
||||||
|
|
||||||
/* 双向链表节点 */
|
/* 双向链表节点 */
|
||||||
struct doublyListNode {
|
struct doublyListNode {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Gonglja (glj0@outlook.com)
|
* Author: Gonglja (glj0@outlook.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.h"
|
#include "../utils/common.h"
|
||||||
|
|
||||||
/* 基于链表实现的队列 */
|
/* 基于链表实现的队列 */
|
||||||
struct linkedListQueue {
|
struct linkedListQueue {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Zero (glj0@outlook.com)
|
* Author: Zero (glj0@outlook.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.h"
|
#include "../utils/common.h"
|
||||||
|
|
||||||
/* 基于链表实现的栈 */
|
/* 基于链表实现的栈 */
|
||||||
struct linkedListStack {
|
struct linkedListStack {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Reanon (793584285@qq.com)
|
* Author: Reanon (793584285@qq.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.h"
|
#include "../utils/common.h"
|
||||||
|
|
||||||
/* AVL Tree */
|
/* AVL Tree */
|
||||||
struct aVLTree {
|
struct aVLTree {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Reanon (793584285@qq.com)
|
* Author: Reanon (793584285@qq.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.h"
|
#include "../utils/common.h"
|
||||||
|
|
||||||
/* 二叉搜索树 */
|
/* 二叉搜索树 */
|
||||||
struct binarySearchTree {
|
struct binarySearchTree {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Reanon (793584285@qq.com)
|
* Author: Reanon (793584285@qq.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.h"
|
#include "../utils/common.h"
|
||||||
|
|
||||||
/* Driver Code */
|
/* Driver Code */
|
||||||
int main() {
|
int main() {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Reanon (793584285@qq.com)
|
* Author: Reanon (793584285@qq.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.h"
|
#include "../utils/common.h"
|
||||||
|
|
||||||
/* 层序遍历 */
|
/* 层序遍历 */
|
||||||
int *levelOrder(TreeNode *root, int *size) {
|
int *levelOrder(TreeNode *root, int *size) {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Reanon (793584285@qq.com)
|
* Author: Reanon (793584285@qq.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.h"
|
#include "../utils/common.h"
|
||||||
|
|
||||||
/* 辅助数组,用于存储遍历序列 */
|
/* 辅助数组,用于存储遍历序列 */
|
||||||
int *arr;
|
int *arr;
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
add_executable(include
|
|
||||||
include_test.c
|
|
||||||
include.h print_util.h
|
|
||||||
list_node.h tree_node.h
|
|
||||||
uthash.h)
|
|
5
codes/c/utils/CMakeLists.txt
Normal file
5
codes/c/utils/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
add_executable(utils
|
||||||
|
common_test.c
|
||||||
|
common.h print_util.h
|
||||||
|
list_node.h tree_node.h
|
||||||
|
uthash.h)
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* File: include.h
|
* File: common.h
|
||||||
* Created Time: 2022-12-20
|
* Created Time: 2022-12-20
|
||||||
* Author: MolDuM (moldum@163.com)、Reanon (793584285@qq.com)
|
* Author: MolDuM (moldum@163.com)、Reanon (793584285@qq.com)
|
||||||
*/
|
*/
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Reanon (793584285@qq.com)
|
* Author: Reanon (793584285@qq.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "include.h"
|
#include "common.h"
|
||||||
|
|
||||||
void testListNode() {
|
void testListNode() {
|
||||||
int nums[] = {2, 3, 5, 6, 7};
|
int nums[] = {2, 3, 5, 6, 7};
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Krahets (krahets@163.com)
|
* Author: Krahets (krahets@163.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../utils/common.hpp"
|
||||||
|
|
||||||
/* 随机返回一个数组元素 */
|
/* 随机返回一个数组元素 */
|
||||||
int randomAccess(int *nums, int size) {
|
int randomAccess(int *nums, int size) {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Krahets (krahets@163.com)
|
* Author: Krahets (krahets@163.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../utils/common.hpp"
|
||||||
|
|
||||||
/* 在链表的节点 n0 之后插入节点 P */
|
/* 在链表的节点 n0 之后插入节点 P */
|
||||||
void insert(ListNode *n0, ListNode *P) {
|
void insert(ListNode *n0, ListNode *P) {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Krahets (krahets@163.com)
|
* Author: Krahets (krahets@163.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../utils/common.hpp"
|
||||||
|
|
||||||
/* Driver Code */
|
/* Driver Code */
|
||||||
int main() {
|
int main() {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Krahets (krahets@163.com)
|
* Author: Krahets (krahets@163.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../utils/common.hpp"
|
||||||
|
|
||||||
/* 列表类简易实现 */
|
/* 列表类简易实现 */
|
||||||
class MyList {
|
class MyList {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Krahets (krahets@163.com)
|
* Author: Krahets (krahets@163.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../utils/common.hpp"
|
||||||
|
|
||||||
/* 回溯算法:全排列 I */
|
/* 回溯算法:全排列 I */
|
||||||
void backtrack(vector<int> &state, const vector<int> &choices, vector<bool> &selected, vector<vector<int>> &res) {
|
void backtrack(vector<int> &state, const vector<int> &choices, vector<bool> &selected, vector<vector<int>> &res) {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Krahets (krahets@163.com)
|
* Author: Krahets (krahets@163.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../utils/common.hpp"
|
||||||
|
|
||||||
/* 回溯算法:全排列 II */
|
/* 回溯算法:全排列 II */
|
||||||
void backtrack(vector<int> &state, const vector<int> &choices, vector<bool> &selected, vector<vector<int>> &res) {
|
void backtrack(vector<int> &state, const vector<int> &choices, vector<bool> &selected, vector<vector<int>> &res) {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Krahets (krahets@163.com)
|
* Author: Krahets (krahets@163.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../utils/common.hpp"
|
||||||
|
|
||||||
vector<TreeNode *> res;
|
vector<TreeNode *> res;
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Krahets (krahets@163.com)
|
* Author: Krahets (krahets@163.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../utils/common.hpp"
|
||||||
|
|
||||||
vector<TreeNode *> path;
|
vector<TreeNode *> path;
|
||||||
vector<vector<TreeNode *>> res;
|
vector<vector<TreeNode *>> res;
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Krahets (krahets@163.com)
|
* Author: Krahets (krahets@163.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../utils/common.hpp"
|
||||||
|
|
||||||
vector<TreeNode *> path;
|
vector<TreeNode *> path;
|
||||||
vector<vector<TreeNode *>> res;
|
vector<vector<TreeNode *>> res;
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Krahets (krahets@163.com)
|
* Author: Krahets (krahets@163.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../utils/common.hpp"
|
||||||
|
|
||||||
/* 判断当前状态是否为解 */
|
/* 判断当前状态是否为解 */
|
||||||
bool isSolution(vector<TreeNode *> &state) {
|
bool isSolution(vector<TreeNode *> &state) {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Krahets (krahets@163.com)
|
* Author: Krahets (krahets@163.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../utils/common.hpp"
|
||||||
|
|
||||||
/* 二分查找(双闭区间) */
|
/* 二分查找(双闭区间) */
|
||||||
int binarySearch(vector<int> &nums, int target) {
|
int binarySearch(vector<int> &nums, int target) {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Krahets (krahets@163.com)
|
* Author: Krahets (krahets@163.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../utils/common.hpp"
|
||||||
|
|
||||||
/* 函数 */
|
/* 函数 */
|
||||||
int func() {
|
int func() {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Krahets (krahets@163.com)
|
* Author: Krahets (krahets@163.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../utils/common.hpp"
|
||||||
|
|
||||||
/* 常数阶 */
|
/* 常数阶 */
|
||||||
int constant(int n) {
|
int constant(int n) {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Krahets (krahets@163.com)
|
* Author: Krahets (krahets@163.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../utils/common.hpp"
|
||||||
|
|
||||||
/* 生成一个数组,元素为 { 1, 2, ..., n },顺序被打乱 */
|
/* 生成一个数组,元素为 { 1, 2, ..., n },顺序被打乱 */
|
||||||
vector<int> randomNumbers(int n) {
|
vector<int> randomNumbers(int n) {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: what-is-me (whatisme@outlook.jp), Krahets (krahets@163.com)
|
* Author: what-is-me (whatisme@outlook.jp), Krahets (krahets@163.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../utils/common.hpp"
|
||||||
|
|
||||||
/* 基于邻接表实现的无向图类 */
|
/* 基于邻接表实现的无向图类 */
|
||||||
class GraphAdjList {
|
class GraphAdjList {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: what-is-me (whatisme@outlook.jp)
|
* Author: what-is-me (whatisme@outlook.jp)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../utils/common.hpp"
|
||||||
|
|
||||||
/* 基于邻接矩阵实现的无向图类 */
|
/* 基于邻接矩阵实现的无向图类 */
|
||||||
class GraphAdjMat {
|
class GraphAdjMat {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Krahets (krahets@163.com)
|
* Author: Krahets (krahets@163.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../utils/common.hpp"
|
||||||
#include "./graph_adjacency_list.cpp"
|
#include "./graph_adjacency_list.cpp"
|
||||||
|
|
||||||
/* 广度优先遍历 BFS */
|
/* 广度优先遍历 BFS */
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Krahets (krahets@163.com)
|
* Author: Krahets (krahets@163.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../utils/common.hpp"
|
||||||
#include "./graph_adjacency_list.cpp"
|
#include "./graph_adjacency_list.cpp"
|
||||||
|
|
||||||
/* 深度优先遍历 DFS 辅助函数 */
|
/* 深度优先遍历 DFS 辅助函数 */
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: msk397 (machangxinq@gmail.com)
|
* Author: msk397 (machangxinq@gmail.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../utils/common.hpp"
|
||||||
|
|
||||||
/* 键值对 int->String */
|
/* 键值对 int->String */
|
||||||
struct Entry {
|
struct Entry {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: msk397 (machangxinq@gmail.com)
|
* Author: msk397 (machangxinq@gmail.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../utils/common.hpp"
|
||||||
|
|
||||||
/* Driver Code */
|
/* Driver Code */
|
||||||
int main() {
|
int main() {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: LoneRanger(836253168@qq.com)
|
* Author: LoneRanger(836253168@qq.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../utils/common.hpp"
|
||||||
|
|
||||||
void testPush(priority_queue<int> &heap, int val) {
|
void testPush(priority_queue<int> &heap, int val) {
|
||||||
heap.push(val); // 元素入堆
|
heap.push(val); // 元素入堆
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: LoneRanger (836253168@qq.com), what-is-me (whatisme@outlook.jp)
|
* Author: LoneRanger (836253168@qq.com), what-is-me (whatisme@outlook.jp)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../utils/common.hpp"
|
||||||
|
|
||||||
/* 大顶堆 */
|
/* 大顶堆 */
|
||||||
class MaxHeap {
|
class MaxHeap {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Krahets (krahets@163.com)
|
* Author: Krahets (krahets@163.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../utils/common.hpp"
|
||||||
|
|
||||||
/* 哈希查找(数组) */
|
/* 哈希查找(数组) */
|
||||||
int hashingSearchArray(unordered_map<int, int> map, int target) {
|
int hashingSearchArray(unordered_map<int, int> map, int target) {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Krahets (krahets@163.com)
|
* Author: Krahets (krahets@163.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../utils/common.hpp"
|
||||||
|
|
||||||
/* 方法一:暴力枚举 */
|
/* 方法一:暴力枚举 */
|
||||||
vector<int> twoSumBruteForce(vector<int> &nums, int target) {
|
vector<int> twoSumBruteForce(vector<int> &nums, int target) {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Krahets (krahets@163.com)
|
* Author: Krahets (krahets@163.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../utils/common.hpp"
|
||||||
|
|
||||||
/* 线性查找(数组) */
|
/* 线性查找(数组) */
|
||||||
int linearSearchArray(vector<int> &nums, int target) {
|
int linearSearchArray(vector<int> &nums, int target) {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Krahets (krahets@163.com)
|
* Author: Krahets (krahets@163.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../utils/common.hpp"
|
||||||
|
|
||||||
/* 冒泡排序 */
|
/* 冒泡排序 */
|
||||||
void bubbleSort(vector<int> &nums) {
|
void bubbleSort(vector<int> &nums) {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Krahets (krahets@163.com)
|
* Author: Krahets (krahets@163.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../utils/common.hpp"
|
||||||
|
|
||||||
/* 桶排序 */
|
/* 桶排序 */
|
||||||
void bucketSort(vector<float> &nums) {
|
void bucketSort(vector<float> &nums) {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Krahets (krahets@163.com)
|
* Author: Krahets (krahets@163.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../utils/common.hpp"
|
||||||
|
|
||||||
/* 计数排序 */
|
/* 计数排序 */
|
||||||
// 简单实现,无法用于排序对象
|
// 简单实现,无法用于排序对象
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Krahets (krahets@163.com)
|
* Author: Krahets (krahets@163.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../utils/common.hpp"
|
||||||
|
|
||||||
/* 插入排序 */
|
/* 插入排序 */
|
||||||
void insertionSort(vector<int> &nums) {
|
void insertionSort(vector<int> &nums) {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Krahets (krahets@163.com)
|
* Author: Krahets (krahets@163.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../utils/common.hpp"
|
||||||
|
|
||||||
/* 合并左子数组和右子数组 */
|
/* 合并左子数组和右子数组 */
|
||||||
// 左子数组区间 [left, mid]
|
// 左子数组区间 [left, mid]
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Krahets (krahets@163.com)
|
* Author: Krahets (krahets@163.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../utils/common.hpp"
|
||||||
|
|
||||||
/* 快速排序类 */
|
/* 快速排序类 */
|
||||||
class QuickSort {
|
class QuickSort {
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
* Author: Krahets (krahets@163.com)
|
* Author: Krahets (krahets@163.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../utils/common.hpp"
|
||||||
|
|
||||||
/* 获取元素 num 的第 k 位,其中 exp = 10^(k-1) */
|
/* 获取元素 num 的第 k 位,其中 exp = 10^(k-1) */
|
||||||
int digit(int num, int exp) {
|
int digit(int num, int exp) {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Krahets (krahets@163.com)
|
* Author: Krahets (krahets@163.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../utils/common.hpp"
|
||||||
|
|
||||||
/* 基于环形数组实现的双向队列 */
|
/* 基于环形数组实现的双向队列 */
|
||||||
class ArrayDeque {
|
class ArrayDeque {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Krahets (krahets@163.com)
|
* Author: Krahets (krahets@163.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../utils/common.hpp"
|
||||||
|
|
||||||
/* 基于环形数组实现的队列 */
|
/* 基于环形数组实现的队列 */
|
||||||
class ArrayQueue {
|
class ArrayQueue {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: qualifier1024 (2539244001@qq.com)
|
* Author: qualifier1024 (2539244001@qq.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../utils/common.hpp"
|
||||||
|
|
||||||
/* 基于数组实现的栈 */
|
/* 基于数组实现的栈 */
|
||||||
class ArrayStack {
|
class ArrayStack {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Krahets (krahets@163.com)
|
* Author: Krahets (krahets@163.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../utils/common.hpp"
|
||||||
|
|
||||||
/* Driver Code */
|
/* Driver Code */
|
||||||
int main() {
|
int main() {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Krahets (krahets@163.com)
|
* Author: Krahets (krahets@163.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../utils/common.hpp"
|
||||||
|
|
||||||
/* 双向链表节点 */
|
/* 双向链表节点 */
|
||||||
struct DoublyListNode {
|
struct DoublyListNode {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Krahets (krahets@163.com)
|
* Author: Krahets (krahets@163.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../utils/common.hpp"
|
||||||
|
|
||||||
/* 基于链表实现的队列 */
|
/* 基于链表实现的队列 */
|
||||||
class LinkedListQueue {
|
class LinkedListQueue {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: qualifier1024 (2539244001@qq.com)
|
* Author: qualifier1024 (2539244001@qq.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../utils/common.hpp"
|
||||||
|
|
||||||
/* 基于链表实现的栈 */
|
/* 基于链表实现的栈 */
|
||||||
class LinkedListStack {
|
class LinkedListStack {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: qualifier1024 (2539244001@qq.com)
|
* Author: qualifier1024 (2539244001@qq.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../utils/common.hpp"
|
||||||
|
|
||||||
/* Driver Code */
|
/* Driver Code */
|
||||||
int main() {
|
int main() {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: qualifier1024 (2539244001@qq.com)
|
* Author: qualifier1024 (2539244001@qq.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../utils/common.hpp"
|
||||||
|
|
||||||
/* Driver Code */
|
/* Driver Code */
|
||||||
int main() {
|
int main() {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: what-is-me (whatisme@outlook.jp)
|
* Author: what-is-me (whatisme@outlook.jp)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../utils/common.hpp"
|
||||||
|
|
||||||
/* AVL 树 */
|
/* AVL 树 */
|
||||||
class AVLTree {
|
class AVLTree {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Krahets (krahets@163.com)
|
* Author: Krahets (krahets@163.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../utils/common.hpp"
|
||||||
|
|
||||||
/* 二叉搜索树 */
|
/* 二叉搜索树 */
|
||||||
class BinarySearchTree {
|
class BinarySearchTree {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Krahets (krahets@163.com)
|
* Author: Krahets (krahets@163.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../utils/common.hpp"
|
||||||
|
|
||||||
/* Driver Code */
|
/* Driver Code */
|
||||||
int main() {
|
int main() {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Krahets (krahets@163.com)
|
* Author: Krahets (krahets@163.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../utils/common.hpp"
|
||||||
|
|
||||||
/* 层序遍历 */
|
/* 层序遍历 */
|
||||||
vector<int> levelOrder(TreeNode *root) {
|
vector<int> levelOrder(TreeNode *root) {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Author: Krahets (krahets@163.com)
|
* Author: Krahets (krahets@163.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../utils/common.hpp"
|
||||||
|
|
||||||
// 初始化列表,用于存储遍历序列
|
// 初始化列表,用于存储遍历序列
|
||||||
vector<int> vec;
|
vector<int> vec;
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
add_executable(include
|
|
||||||
include.hpp PrintUtil.hpp
|
|
||||||
ListNode.hpp TreeNode.hpp
|
|
||||||
Vertex.hpp)
|
|
4
codes/cpp/utils/CMakeLists.txt
Normal file
4
codes/cpp/utils/CMakeLists.txt
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
add_executable(utils
|
||||||
|
common.hpp print_utils.hpp
|
||||||
|
list_node.hpp tree_node.hpp
|
||||||
|
vertex.hpp)
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* File: PrintUtil.hpp
|
* File: common.hpp
|
||||||
* Created Time: 2021-12-19
|
* Created Time: 2021-12-19
|
||||||
* Author: Krahets (krahets@163.com)
|
* Author: Krahets (krahets@163.com)
|
||||||
*/
|
*/
|
||||||
@ -20,9 +20,9 @@
|
|||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "ListNode.hpp"
|
#include "list_node.hpp"
|
||||||
#include "PrintUtil.hpp"
|
#include "print_utils.hpp"
|
||||||
#include "TreeNode.hpp"
|
#include "tree_node.hpp"
|
||||||
#include "Vertex.hpp"
|
#include "vertex.hpp"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* File: PrintUtil.hpp
|
* File: list_node.hpp
|
||||||
* Created Time: 2021-12-19
|
* Created Time: 2021-12-19
|
||||||
* Author: Krahets (krahets@163.com)
|
* Author: Krahets (krahets@163.com)
|
||||||
*/
|
*/
|
@ -1,13 +1,13 @@
|
|||||||
/**
|
/**
|
||||||
* File: PrintUtil.hpp
|
* File: print_utils.hpp
|
||||||
* Created Time: 2021-12-19
|
* Created Time: 2021-12-19
|
||||||
* Author: Krahets (krahets@163.com), msk397 (machangxinq@gmail.com), LoneRanger(836253168@qq.com)
|
* Author: Krahets (krahets@163.com), msk397 (machangxinq@gmail.com), LoneRanger(836253168@qq.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "ListNode.hpp"
|
#include "list_node.hpp"
|
||||||
#include "TreeNode.hpp"
|
#include "tree_node.hpp"
|
||||||
#include <climits>
|
#include <climits>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* File: PrintUtil.hpp
|
* File: tree_node.hpp
|
||||||
* Created Time: 2021-12-19
|
* Created Time: 2021-12-19
|
||||||
* Author: Krahets (krahets@163.com)
|
* Author: Krahets (krahets@163.com)
|
||||||
*/
|
*/
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* File: PrintUtil.hpp
|
* File: vertex.hpp
|
||||||
* Created Time: 2023-03-02
|
* Created Time: 2023-03-02
|
||||||
* Author: Krahets (krahets@163.com)
|
* Author: Krahets (krahets@163.com)
|
||||||
*/
|
*/
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* File: graph_adjacency_list.cs
|
* File: Vertex.cs
|
||||||
* Created Time: 2023-02-06
|
* Created Time: 2023-02-06
|
||||||
* Author: zjkung1123 (zjkung1123@gmail.com), krahets (krahets@163.com)
|
* Author: zjkung1123 (zjkung1123@gmail.com), krahets (krahets@163.com)
|
||||||
*/
|
*/
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* File: ListNode
|
* File: list_node.dart
|
||||||
* Created Time: 2023-01-23
|
* Created Time: 2023-01-23
|
||||||
* Author: Jefferson (JeffersonHuang77@gmail.com)
|
* Author: Jefferson (JeffersonHuang77@gmail.com)
|
||||||
*/
|
*/
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* File: PrintUtil
|
* File: print_util.dart
|
||||||
* Created Time: 2023-01-23
|
* Created Time: 2023-01-23
|
||||||
* Author: Jefferson (JeffersonHuang77@gmail.com)
|
* Author: Jefferson (JeffersonHuang77@gmail.com)
|
||||||
*/
|
*/
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
package chapter_array_and_linkedlist;
|
package chapter_array_and_linkedlist;
|
||||||
|
|
||||||
import include.*;
|
import utils.*;
|
||||||
|
|
||||||
public class linked_list {
|
public class linked_list {
|
||||||
/* 在链表的节点 n0 之后插入节点 P */
|
/* 在链表的节点 n0 之后插入节点 P */
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
package chapter_backtracking;
|
package chapter_backtracking;
|
||||||
|
|
||||||
import include.*;
|
import utils.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class preorder_traversal_i_compact {
|
public class preorder_traversal_i_compact {
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
package chapter_backtracking;
|
package chapter_backtracking;
|
||||||
|
|
||||||
import include.*;
|
import utils.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class preorder_traversal_ii_compact {
|
public class preorder_traversal_ii_compact {
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
package chapter_backtracking;
|
package chapter_backtracking;
|
||||||
|
|
||||||
import include.*;
|
import utils.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class preorder_traversal_iii_compact {
|
public class preorder_traversal_iii_compact {
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
package chapter_backtracking;
|
package chapter_backtracking;
|
||||||
|
|
||||||
import include.*;
|
import utils.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class preorder_traversal_iii_template {
|
public class preorder_traversal_iii_template {
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
package chapter_computational_complexity;
|
package chapter_computational_complexity;
|
||||||
|
|
||||||
import include.*;
|
import utils.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class space_complexity {
|
public class space_complexity {
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user