rename project names;
add stack implementation with csharp
This commit is contained in:
parent
aee7f91373
commit
9b540eb9a8
@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace _05_array
|
namespace algo05_array
|
||||||
{
|
{
|
||||||
public sealed class Array<T> where T : IComparable<T>
|
public sealed class Array<T> where T : IComparable<T>
|
||||||
{
|
{
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netcoreapp2.2</TargetFramework>
|
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||||
|
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
@ -1,7 +1,6 @@
|
|||||||
using System.Text.RegularExpressions;
|
using algo05_array;
|
||||||
using _05_array;
|
|
||||||
|
|
||||||
namespace _06_linked_list
|
namespace algo06_linked_list
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 使用数组实现LRU缓存淘汰算法
|
/// 使用数组实现LRU缓存淘汰算法
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
namespace _06_linked_list
|
namespace algo06_linked_list
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 使用单链表实现LRU缓存淘汰算法
|
/// 使用单链表实现LRU缓存淘汰算法
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace _06_linked_list
|
namespace algo06_linked_list
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 单链表的插入、删除、清空、查找
|
/// 单链表的插入、删除、清空、查找
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\05-array\_05_array.csproj" />
|
<ProjectReference Include="..\05-array\algo05_array.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
@ -1,7 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using _06_linked_list;
|
using algo06_linked_list;
|
||||||
|
|
||||||
namespace _07_linkedlist
|
namespace algo07_linkedlist
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 单链表常用算法操作
|
/// 单链表常用算法操作
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\06-linkedlist\_06_linked_list.csproj" />
|
<ProjectReference Include="..\..\06-linkedlist\algo06_linked_list.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
41
csharp/08-stack/algo08_stack/ArrayStack.cs
Normal file
41
csharp/08-stack/algo08_stack/ArrayStack.cs
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
51
csharp/08-stack/algo08_stack/LinkedStack.cs
Normal file
51
csharp/08-stack/algo08_stack/LinkedStack.cs
Normal file
@ -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; }
|
||||||
|
}
|
||||||
|
}
|
39
csharp/08-stack/algo08_stack/LinkedStackBrowser.cs
Normal file
39
csharp/08-stack/algo08_stack/LinkedStackBrowser.cs
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
7
csharp/08-stack/algo08_stack/algo08_stack.csproj
Normal file
7
csharp/08-stack/algo08_stack/algo08_stack.csproj
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
@ -1,7 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using algo05_array;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using Xunit.Abstractions;
|
using Xunit.Abstractions;
|
||||||
using _05_array;
|
|
||||||
|
|
||||||
namespace _05_array_tests
|
namespace _05_array_tests
|
||||||
{
|
{
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\05-array\_05_array.csproj" />
|
<ProjectReference Include="..\..\05-array\algo05_array.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
@ -1,7 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using _06_linked_list;
|
using algo06_linked_list;
|
||||||
|
|
||||||
namespace _06_linkedlist_tests
|
namespace algo06_linkedlist_tests
|
||||||
{
|
{
|
||||||
public class BaseLinkedListTests
|
public class BaseLinkedListTests
|
||||||
{
|
{
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
|
using algo05_array;
|
||||||
|
using algo06_linked_list;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using Xunit.Abstractions;
|
using Xunit.Abstractions;
|
||||||
using _05_array;
|
|
||||||
using _06_linked_list;
|
|
||||||
|
|
||||||
namespace _06_linkedlist_tests
|
namespace algo06_linkedlist_tests
|
||||||
{
|
{
|
||||||
public class LRUWithArrayTests
|
public class LRUWithArrayTests
|
||||||
{
|
{
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
using Xunit;
|
using Xunit;
|
||||||
using Xunit.Abstractions;
|
using Xunit.Abstractions;
|
||||||
using _06_linked_list;
|
using algo06_linked_list;
|
||||||
|
|
||||||
namespace _06_linkedlist_tests
|
namespace algo06_linkedlist_tests
|
||||||
{
|
{
|
||||||
public class LRUWithLinkedListTests : BaseLinkedListTests
|
public class LRUWithLinkedListTests : BaseLinkedListTests
|
||||||
{
|
{
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using Xunit.Abstractions;
|
using Xunit.Abstractions;
|
||||||
using _06_linked_list;
|
using algo06_linked_list;
|
||||||
|
|
||||||
namespace _06_linkedlist_tests
|
namespace algo06_linkedlist_tests
|
||||||
{
|
{
|
||||||
public class SingleLinkedListTests : BaseLinkedListTests
|
public class SingleLinkedListTests : BaseLinkedListTests
|
||||||
{
|
{
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netcoreapp2.2</TargetFramework>
|
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||||
<RootNamespace>_06_linkedlist_tests</RootNamespace>
|
|
||||||
|
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
@ -14,8 +13,8 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\05-array\_05_array.csproj" />
|
<ProjectReference Include="..\..\05-array\algo05_array.csproj" />
|
||||||
<ProjectReference Include="..\..\06-linkedlist\_06_linked_list.csproj" />
|
<ProjectReference Include="..\..\06-linkedlist\algo06_linked_list.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
@ -1,10 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using _06_linkedlist_tests;
|
using algo06_linkedlist_tests;
|
||||||
using _06_linked_list;
|
using algo06_linked_list;
|
||||||
using _07_linkedlist;
|
using algo07_linkedlist;
|
||||||
|
|
||||||
namespace _07_linkedlist_tests
|
namespace algo07_linkedlist_tests
|
||||||
{
|
{
|
||||||
public class SingleLinkedListAlgoTests : BaseLinkedListTests
|
public class SingleLinkedListAlgoTests : BaseLinkedListTests
|
||||||
{
|
{
|
||||||
|
@ -13,9 +13,9 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\06-linkedlist\_06_linked_list.csproj" />
|
<ProjectReference Include="..\..\06-linkedlist\algo06_linked_list.csproj" />
|
||||||
<ProjectReference Include="..\..\07-linkedlist\_07_linkedlist\_07_linkedlist.csproj" />
|
<ProjectReference Include="..\..\07-linkedlist\_07_linkedlist\algo07_linkedlist.csproj" />
|
||||||
<ProjectReference Include="..\_06_linkedlist_tests\_06_linkedlist_tests.csproj" />
|
<ProjectReference Include="..\_06_linkedlist_tests\algo06_linkedlist_tests.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
81
csharp/Tests/algo08_stack_tests/ArrayStack.Tests.cs
Normal file
81
csharp/Tests/algo08_stack_tests/ArrayStack.Tests.cs
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
using System;
|
||||||
|
using algo08_stack;
|
||||||
|
using Xunit;
|
||||||
|
using Xunit.Abstractions;
|
||||||
|
|
||||||
|
namespace algo08_stack_tests
|
||||||
|
{
|
||||||
|
public class ArrayStackTests
|
||||||
|
{
|
||||||
|
private readonly ITestOutputHelper _output;
|
||||||
|
|
||||||
|
public ArrayStackTests(ITestOutputHelper output)
|
||||||
|
{
|
||||||
|
_output = output;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PrintStackArray<T>(ArrayStack<T> list)
|
||||||
|
{
|
||||||
|
if (list.Count == 0) return;
|
||||||
|
|
||||||
|
while (list.Count > 0)
|
||||||
|
{
|
||||||
|
T item = list.Pop();
|
||||||
|
_output.WriteLine(item.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Push_3_Elements_Then_Length_Equal_3()
|
||||||
|
{
|
||||||
|
var stack = new ArrayStack<int>(5);
|
||||||
|
stack.Push(2);
|
||||||
|
stack.Push(4);
|
||||||
|
stack.Push(6);
|
||||||
|
|
||||||
|
Assert.Equal(3, stack.Count);
|
||||||
|
|
||||||
|
PrintStackArray(stack);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Push_Throw_InvalidOperationException_When_Stack_Full()
|
||||||
|
{
|
||||||
|
var stack = new ArrayStack<int>(5);
|
||||||
|
stack.Push(2);
|
||||||
|
stack.Push(4);
|
||||||
|
stack.Push(6);
|
||||||
|
stack.Push(8);
|
||||||
|
stack.Push(10);
|
||||||
|
|
||||||
|
Exception ex = Assert.Throws<InvalidOperationException>(() => stack.Push(11));
|
||||||
|
Assert.IsType<InvalidOperationException>(ex);
|
||||||
|
|
||||||
|
PrintStackArray(stack);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Pop_Throw_InvalidOperationException_When_Stack_Empty()
|
||||||
|
{
|
||||||
|
var stack = new ArrayStack<int>(5);
|
||||||
|
|
||||||
|
Exception ex = Assert.Throws<InvalidOperationException>(() => stack.Pop());
|
||||||
|
Assert.IsType<InvalidOperationException>(ex);
|
||||||
|
|
||||||
|
PrintStackArray(stack);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Pop_Valid_When_Stack_Not_Empty()
|
||||||
|
{
|
||||||
|
var stack = new ArrayStack<int>(5);
|
||||||
|
stack.Push(2);
|
||||||
|
stack.Push(4);
|
||||||
|
|
||||||
|
int val = stack.Pop();
|
||||||
|
Assert.Equal(4, val);
|
||||||
|
|
||||||
|
PrintStackArray(stack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
65
csharp/Tests/algo08_stack_tests/LinkedStack.Tests.cs
Normal file
65
csharp/Tests/algo08_stack_tests/LinkedStack.Tests.cs
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
using System;
|
||||||
|
using algo08_stack;
|
||||||
|
using Xunit;
|
||||||
|
using Xunit.Abstractions;
|
||||||
|
|
||||||
|
namespace algo08_stack_tests
|
||||||
|
{
|
||||||
|
public class LinkedStackTests
|
||||||
|
{
|
||||||
|
private readonly ITestOutputHelper _output;
|
||||||
|
|
||||||
|
public LinkedStackTests(ITestOutputHelper output)
|
||||||
|
{
|
||||||
|
_output = output;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PrintStackLinkedList<T>(LinkedStack<T> list)
|
||||||
|
{
|
||||||
|
if (list.Count == 0) return;
|
||||||
|
|
||||||
|
while (list.Count > 0)
|
||||||
|
{
|
||||||
|
var val = list.Pop();
|
||||||
|
_output.WriteLine(val.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Push_3_Elements_Then_Length_Equal_3()
|
||||||
|
{
|
||||||
|
var stack = new LinkedStack<int>();
|
||||||
|
stack.Push(2);
|
||||||
|
stack.Push(4);
|
||||||
|
stack.Push(6);
|
||||||
|
|
||||||
|
Assert.Equal(3, stack.Count);
|
||||||
|
|
||||||
|
PrintStackLinkedList(stack);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Pop_Throw_InvalidOperationException_When_Stack_Empty()
|
||||||
|
{
|
||||||
|
var stack = new LinkedStack<int>();
|
||||||
|
|
||||||
|
Exception ex = Assert.Throws<InvalidOperationException>(() => stack.Pop());
|
||||||
|
Assert.IsType<InvalidOperationException>(ex);
|
||||||
|
|
||||||
|
PrintStackLinkedList(stack);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Pop_Valid_When_Stack_Not_Empty()
|
||||||
|
{
|
||||||
|
var stack = new LinkedStack<int>();
|
||||||
|
stack.Push(2);
|
||||||
|
stack.Push(4);
|
||||||
|
|
||||||
|
var nodeVal = stack.Pop();
|
||||||
|
Assert.Equal(4, nodeVal);
|
||||||
|
|
||||||
|
PrintStackLinkedList(stack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
107
csharp/Tests/algo08_stack_tests/LinkedStackBrowser.Tests.cs
Normal file
107
csharp/Tests/algo08_stack_tests/LinkedStackBrowser.Tests.cs
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
using algo08_stack;
|
||||||
|
using Xunit;
|
||||||
|
using Xunit.Abstractions;
|
||||||
|
|
||||||
|
namespace algo08_stack_tests
|
||||||
|
{
|
||||||
|
public class LinkedStackBrowserTests
|
||||||
|
{
|
||||||
|
private readonly ITestOutputHelper _output;
|
||||||
|
|
||||||
|
public LinkedStackBrowserTests(ITestOutputHelper output)
|
||||||
|
{
|
||||||
|
_output = output;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Browser_Open_4_Links_Back_2_Return_Right_Link()
|
||||||
|
{
|
||||||
|
var browser = new LinkedStackBrowser();
|
||||||
|
browser.Open("www.google.com");
|
||||||
|
browser.Open("www.baidu.com");
|
||||||
|
browser.Open("www.qq.com");
|
||||||
|
browser.Open("www.dadu.com");
|
||||||
|
|
||||||
|
string url = browser.Backward();
|
||||||
|
url = browser.Backward();
|
||||||
|
|
||||||
|
Assert.Equal("www.qq.com", url);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Browser_Open_4_Links_Back_4_Return_Empty()
|
||||||
|
{
|
||||||
|
var browser = new LinkedStackBrowser();
|
||||||
|
browser.Open("www.google.com");
|
||||||
|
browser.Open("www.baidu.com");
|
||||||
|
browser.Open("www.qq.com");
|
||||||
|
browser.Open("www.dadu.com");
|
||||||
|
|
||||||
|
browser.Backward();
|
||||||
|
browser.Backward();
|
||||||
|
browser.Backward();
|
||||||
|
browser.Backward();
|
||||||
|
string url = browser.Backward();
|
||||||
|
|
||||||
|
Assert.Equal(string.Empty, url);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Browser_Forward_Before_End()
|
||||||
|
{
|
||||||
|
var browser = new LinkedStackBrowser();
|
||||||
|
browser.Open("www.google.com");
|
||||||
|
browser.Open("www.baidu.com");
|
||||||
|
browser.Open("www.qq.com");
|
||||||
|
browser.Open("www.dadu.com");
|
||||||
|
|
||||||
|
browser.Backward();
|
||||||
|
browser.Backward();
|
||||||
|
browser.Backward();
|
||||||
|
|
||||||
|
browser.Forward();
|
||||||
|
string url = browser.Forward();
|
||||||
|
|
||||||
|
Assert.Equal("www.qq.com", url);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Browser_Forward_Until_End()
|
||||||
|
{
|
||||||
|
var browser = new LinkedStackBrowser();
|
||||||
|
browser.Open("www.google.com");
|
||||||
|
browser.Open("www.baidu.com");
|
||||||
|
browser.Open("www.qq.com");
|
||||||
|
browser.Open("www.dadu.com");
|
||||||
|
|
||||||
|
browser.Backward();
|
||||||
|
browser.Backward();
|
||||||
|
browser.Backward();
|
||||||
|
|
||||||
|
browser.Forward();
|
||||||
|
browser.Forward();
|
||||||
|
browser.Forward();
|
||||||
|
string url = browser.Forward();
|
||||||
|
|
||||||
|
Assert.Equal(string.Empty, url);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Browser_Backward_And_Open_New_Then_Cannot_Forward()
|
||||||
|
{
|
||||||
|
var browser = new LinkedStackBrowser();
|
||||||
|
browser.Open("www.google.com");
|
||||||
|
browser.Open("www.baidu.com");
|
||||||
|
browser.Open("www.qq.com");
|
||||||
|
|
||||||
|
browser.Backward();
|
||||||
|
browser.Backward();
|
||||||
|
|
||||||
|
browser.Open("www.dadu.com");
|
||||||
|
|
||||||
|
string url = browser.Forward();
|
||||||
|
|
||||||
|
Assert.Equal(string.Empty, url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
19
csharp/Tests/algo08_stack_tests/algo08_stack_tests.csproj
Normal file
19
csharp/Tests/algo08_stack_tests/algo08_stack_tests.csproj
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||||
|
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
|
||||||
|
<PackageReference Include="xunit" Version="2.4.0" />
|
||||||
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\08-stack\algo08_stack\algo08_stack.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
@ -3,19 +3,23 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||||||
# Visual Studio 15
|
# Visual Studio 15
|
||||||
VisualStudioVersion = 15.0.26124.0
|
VisualStudioVersion = 15.0.26124.0
|
||||||
MinimumVisualStudioVersion = 15.0.26124.0
|
MinimumVisualStudioVersion = 15.0.26124.0
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "_05_array", "05-array\_05_array.csproj", "{B88033F6-FF08-434A-AED7-91F5CDB73402}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "algo05_array", "05-array\algo05_array.csproj", "{B88033F6-FF08-434A-AED7-91F5CDB73402}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "_06_linked_list", "06-linkedlist\_06_linked_list.csproj", "{29CABAFB-2581-42D1-ABD9-F0D9E0BB8DC2}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "algo06_linked_list", "06-linkedlist\algo06_linked_list.csproj", "{29CABAFB-2581-42D1-ABD9-F0D9E0BB8DC2}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{B0248987-EEDF-4D93-8E12-C00B1EB5B6CB}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{B0248987-EEDF-4D93-8E12-C00B1EB5B6CB}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "_05_array_tests", "Tests\_05_array_tests\_05_array_tests.csproj", "{14982212-49E4-4409-8BFD-2D8A2945BD83}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "algo05_array_tests", "Tests\_05_array_tests\algo05_array_tests.csproj", "{14982212-49E4-4409-8BFD-2D8A2945BD83}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "_06_linkedlist_tests", "Tests\_06_linkedlist_tests\_06_linkedlist_tests.csproj", "{1B93D9C6-D6C1-4619-BFB9-D84C29099223}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "algo06_linkedlist_tests", "Tests\_06_linkedlist_tests\algo06_linkedlist_tests.csproj", "{1B93D9C6-D6C1-4619-BFB9-D84C29099223}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "_07_linkedlist", "07-linkedlist\_07_linkedlist\_07_linkedlist.csproj", "{5A4CCBB9-F683-4436-AAEE-4B3ABA76936B}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "algo07_linkedlist", "07-linkedlist\_07_linkedlist\algo07_linkedlist.csproj", "{5A4CCBB9-F683-4436-AAEE-4B3ABA76936B}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "_07_linkedlist_tests", "Tests\_07_linkedlist_tests\_07_linkedlist_tests.csproj", "{66C3BC00-C135-4279-A666-A330A86F20D5}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "algo07_linkedlist_tests", "Tests\_07_linkedlist_tests\algo07_linkedlist_tests.csproj", "{66C3BC00-C135-4279-A666-A330A86F20D5}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "algo08_stack", "08-stack\algo08_stack\algo08_stack.csproj", "{E080D481-C98E-43F3-B1D1-51DCF4CF7146}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "algo08_stack_tests", "Tests\algo08_stack_tests\algo08_stack_tests.csproj", "{6A249475-54EA-4039-9B0C-DC0E0A884C07}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@ -102,10 +106,35 @@ Global
|
|||||||
{66C3BC00-C135-4279-A666-A330A86F20D5}.Release|x64.Build.0 = Release|Any CPU
|
{66C3BC00-C135-4279-A666-A330A86F20D5}.Release|x64.Build.0 = Release|Any CPU
|
||||||
{66C3BC00-C135-4279-A666-A330A86F20D5}.Release|x86.ActiveCfg = Release|Any CPU
|
{66C3BC00-C135-4279-A666-A330A86F20D5}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
{66C3BC00-C135-4279-A666-A330A86F20D5}.Release|x86.Build.0 = Release|Any CPU
|
{66C3BC00-C135-4279-A666-A330A86F20D5}.Release|x86.Build.0 = Release|Any CPU
|
||||||
|
{E080D481-C98E-43F3-B1D1-51DCF4CF7146}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{E080D481-C98E-43F3-B1D1-51DCF4CF7146}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{E080D481-C98E-43F3-B1D1-51DCF4CF7146}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||||
|
{E080D481-C98E-43F3-B1D1-51DCF4CF7146}.Debug|x64.Build.0 = Debug|Any CPU
|
||||||
|
{E080D481-C98E-43F3-B1D1-51DCF4CF7146}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{E080D481-C98E-43F3-B1D1-51DCF4CF7146}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
|
{E080D481-C98E-43F3-B1D1-51DCF4CF7146}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{E080D481-C98E-43F3-B1D1-51DCF4CF7146}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{E080D481-C98E-43F3-B1D1-51DCF4CF7146}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
|
{E080D481-C98E-43F3-B1D1-51DCF4CF7146}.Release|x64.Build.0 = Release|Any CPU
|
||||||
|
{E080D481-C98E-43F3-B1D1-51DCF4CF7146}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{E080D481-C98E-43F3-B1D1-51DCF4CF7146}.Release|x86.Build.0 = Release|Any CPU
|
||||||
|
{6A249475-54EA-4039-9B0C-DC0E0A884C07}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{6A249475-54EA-4039-9B0C-DC0E0A884C07}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{6A249475-54EA-4039-9B0C-DC0E0A884C07}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||||
|
{6A249475-54EA-4039-9B0C-DC0E0A884C07}.Debug|x64.Build.0 = Debug|Any CPU
|
||||||
|
{6A249475-54EA-4039-9B0C-DC0E0A884C07}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{6A249475-54EA-4039-9B0C-DC0E0A884C07}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
|
{6A249475-54EA-4039-9B0C-DC0E0A884C07}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{6A249475-54EA-4039-9B0C-DC0E0A884C07}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{6A249475-54EA-4039-9B0C-DC0E0A884C07}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
|
{6A249475-54EA-4039-9B0C-DC0E0A884C07}.Release|x64.Build.0 = Release|Any CPU
|
||||||
|
{6A249475-54EA-4039-9B0C-DC0E0A884C07}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{6A249475-54EA-4039-9B0C-DC0E0A884C07}.Release|x86.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(NestedProjects) = preSolution
|
GlobalSection(NestedProjects) = preSolution
|
||||||
{14982212-49E4-4409-8BFD-2D8A2945BD83} = {B0248987-EEDF-4D93-8E12-C00B1EB5B6CB}
|
{14982212-49E4-4409-8BFD-2D8A2945BD83} = {B0248987-EEDF-4D93-8E12-C00B1EB5B6CB}
|
||||||
{1B93D9C6-D6C1-4619-BFB9-D84C29099223} = {B0248987-EEDF-4D93-8E12-C00B1EB5B6CB}
|
{1B93D9C6-D6C1-4619-BFB9-D84C29099223} = {B0248987-EEDF-4D93-8E12-C00B1EB5B6CB}
|
||||||
{66C3BC00-C135-4279-A666-A330A86F20D5} = {B0248987-EEDF-4D93-8E12-C00B1EB5B6CB}
|
{66C3BC00-C135-4279-A666-A330A86F20D5} = {B0248987-EEDF-4D93-8E12-C00B1EB5B6CB}
|
||||||
|
{6A249475-54EA-4039-9B0C-DC0E0A884C07} = {B0248987-EEDF-4D93-8E12-C00B1EB5B6CB}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
Loading…
Reference in New Issue
Block a user