forked from wangzheng0822/algo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request wangzheng0822#3 from wangzheng0822/master
merge
- Loading branch information
Showing
49 changed files
with
1,610 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,74 @@ | ||
# 数据结构和算法之美 | ||
# [https://time.geekbang.org/column/intro/126](https://time.geekbang.org/column/intro/126) | ||
# 数据结构和算法必知必会的50个代码实现 | ||
|
||
# Java rate limiting library/framework | ||
# https://github.com/wangzheng0822/ratelimiter4j | ||
## 数组 | ||
* 实现一个支持动态扩容的数组 | ||
* 实现一个大小固定的有序数组,支持动态增删改操作 | ||
* 实现两个有序数组合并为一个有序数组 | ||
|
||
## 链表 | ||
* 实现单链表、循环链表、双向链表,支持增删操作 | ||
* 实现单链表反转 | ||
* 实现两个有序的链表合并为一个有序链表 | ||
* 实现求链表的中间结点 | ||
|
||
## 栈 | ||
* 用数组实现一个顺序栈 | ||
* 用链表实现一个链式栈 | ||
* 编程模拟实现一个浏览器的前进、后退功能 | ||
|
||
## 队列 | ||
* 用数组实现一个顺序队列 | ||
* 用链表实现一个链式队列 | ||
* 实现一个循环队列 | ||
|
||
## 递归 | ||
* 编程实现斐波那契数列求值f(n)=f(n-1)+f(n-2) | ||
* 编程实现求阶乘n! | ||
* 编程实现一组数据集合的全排列 | ||
|
||
## 排序 | ||
* 实现归并排序、快速排序、插入排序、冒泡排序、选择排序 | ||
* 编程实现O(n)时间复杂度内找到一组数据的第K大元素 | ||
|
||
## 二分查找 | ||
* 实现一个有序数组的二分查找算法 | ||
* 实现模糊二分查找算法(比如大于等于给定值的第一个元素) | ||
|
||
## 散列表 | ||
* 实现一个基于链表法解决冲突问题的散列表 | ||
* 实现一个LRU缓存淘汰算法 | ||
|
||
## 字符串 | ||
* 实现一个字符集,只包含a~z这26个英文字母的Trie树 | ||
* 实现朴素的字符串匹配算法 | ||
|
||
## 二叉树 | ||
* 实现一个二叉查找树,并且支持插入、删除、查找操作 | ||
* 实现查找二叉查找树中某个节点的后继、前驱节点 | ||
* 实现二叉树前、中、后序以及按层遍历 | ||
|
||
## 堆 | ||
* 实现一个小顶堆、大顶堆、优先级队列 | ||
* 实现堆排序 | ||
* 利用优先级队列合并K个有序数组 | ||
* 求一组动态数据集合的最大Top K | ||
|
||
## 图 | ||
* 实现有向图、无向图、有权图、无权图的邻接矩阵和邻接表表示方法 | ||
* 实现图的深度优先搜索、广度优先搜索 | ||
* 实现Dijkstra算法、A*算法 | ||
* 实现拓扑排序的Kahn算法、DFS算法 | ||
|
||
## 回溯 | ||
* 利用回溯算法求解八皇后问题 | ||
* 利用回溯算法求解0-1背包问题 | ||
|
||
## 分治 | ||
* 利用分治算法求一组数据的逆序对个数 | ||
|
||
## 动态规划 | ||
* 0-1背包问题 | ||
* 最小路径和 | ||
* 编程实现莱文斯坦最短编辑距离 | ||
* 编程实现查找两个字符串的最长公共子序列 | ||
* 编程实现一个数据序列的最长递增子序列 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
namespace _06_linked_list | ||
namespace algo06_linked_list | ||
{ | ||
/// <summary> | ||
/// 使用单链表实现LRU缓存淘汰算法 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
using System; | ||
|
||
namespace _06_linked_list | ||
namespace algo06_linked_list | ||
{ | ||
/// <summary> | ||
/// 单链表的插入、删除、清空、查找 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System; | ||
|
||
namespace algo08_stack | ||
{ | ||
public class ArrayStack<T> | ||
{ | ||
private readonly int _capacity; | ||
|
||
private readonly T[] _data; | ||
|
||
private int _top = -1; // 指向栈顶元素,当为-1时表示栈为空 | ||
|
||
public ArrayStack(int capacity) | ||
{ | ||
_capacity = capacity; | ||
|
||
_data = new T[capacity]; | ||
} | ||
|
||
public int Count => _top + 1; | ||
|
||
public void Push(T val) | ||
{ | ||
if (Count == _capacity) throw new InvalidOperationException("Stack full."); | ||
|
||
_top++; | ||
|
||
_data[_top] = val; | ||
} | ||
|
||
public T Pop() | ||
{ | ||
if (_top == -1) throw new InvalidOperationException("Stack empty."); | ||
|
||
T val = _data[_top]; | ||
_top--; | ||
|
||
return val; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System; | ||
|
||
namespace algo08_stack | ||
{ | ||
public class LinkedStack<T> | ||
{ | ||
private StackListNode<T> _top; | ||
|
||
public int Count { get; private set; } | ||
|
||
public void Push(T val) | ||
{ | ||
var newNode = new StackListNode<T>(val); | ||
newNode.Next = _top; | ||
_top = newNode; | ||
|
||
Count++; | ||
} | ||
|
||
public T Pop() | ||
{ | ||
if (_top == null) throw new InvalidOperationException("Stack empty"); | ||
|
||
T val = _top.Value; | ||
_top = _top.Next; | ||
|
||
Count--; | ||
|
||
return val; | ||
} | ||
|
||
public void Clear() | ||
{ | ||
while (Count > 0) | ||
{ | ||
Pop(); | ||
} | ||
} | ||
} | ||
|
||
public class StackListNode<T> | ||
{ | ||
public StackListNode(T nodeValue) | ||
{ | ||
Value = nodeValue; | ||
} | ||
|
||
public T Value { get; set; } | ||
public StackListNode<T> Next { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
namespace algo08_stack | ||
{ | ||
/// <summary> | ||
/// 利用链栈实现浏览器怎么进后退 | ||
/// </summary> | ||
public class LinkedStackBrowser | ||
{ | ||
private readonly LinkedStack<string> _backStack = new LinkedStack<string>(); | ||
private readonly LinkedStack<string> _forwardStack = new LinkedStack<string>(); | ||
|
||
public void Open(string url) | ||
{ | ||
_backStack.Push(url); | ||
|
||
_forwardStack.Clear(); | ||
} | ||
|
||
public string Backward() | ||
{ | ||
if (_backStack.Count == 0) return string.Empty; | ||
|
||
string url = _backStack.Pop(); | ||
|
||
_forwardStack.Push(url); | ||
|
||
return url; | ||
} | ||
|
||
public string Forward() | ||
{ | ||
if (_forwardStack.Count == 0) return string.Empty; | ||
|
||
string url = _forwardStack.Pop(); | ||
_backStack.Push(url); | ||
|
||
return url; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.2</TargetFramework> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
csharp/Tests/_07_linkedlist_tests/SingleLinkedListAlgo.Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.