Skip to content

Commit 7e78bc3

Browse files
authored
Merge pull request #123 from ikesnowy/Day42
Day42
2 parents c6e1e55 + 95b12d6 commit 7e78bc3

File tree

11 files changed

+349
-18
lines changed

11 files changed

+349
-18
lines changed

1 Fundamental/1.3/1.3.33/Deque.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ public void PushLeft(Item item)
6565
{
6666
this.last = this.first;
6767
}
68+
else
69+
{
70+
oldFirst.prev = this.first;
71+
}
6872
this.count++;
6973
}
7074

1 Fundamental/1.3/1.3.48/1.3.48.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
<Reference Include="System.Xml" />
4343
</ItemGroup>
4444
<ItemGroup>
45-
<Compile Include="Deque.cs" />
45+
<Compile Include="DeStack.cs" />
4646
<Compile Include="Program.cs" />
4747
<Compile Include="Properties\AssemblyInfo.cs" />
4848
</ItemGroup>

1 Fundamental/1.3/1.3.48/Deque.cs renamed to 1 Fundamental/1.3/1.3.48/DeStack.cs

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace _1._3._48
99
{
10-
public class Deque<Item> : IEnumerable<Item>
10+
public class DeStack<Item> : IEnumerable<Item>
1111
{
1212
private class DoubleNode<T>
1313
{
@@ -18,34 +18,54 @@ private class DoubleNode<T>
1818

1919
DoubleNode<Item> first;
2020
DoubleNode<Item> last;
21-
int count;
21+
int leftcount;
22+
int rightcount;
2223

2324
/// <summary>
24-
/// 默认构造函数,建立一个双端队列
25+
/// 默认构造函数,建立一个双端栈
2526
/// </summary>
26-
public Deque()
27+
public DeStack()
2728
{
2829
this.first = null;
2930
this.last = null;
30-
this.count = 0;
31+
this.leftcount = 0;
32+
this.rightcount = 0;
3133
}
3234

3335
/// <summary>
34-
/// 检查队列是否为空
36+
/// 检查左侧栈是否为空
3537
/// </summary>
3638
/// <returns></returns>
37-
public bool IsEmpty()
39+
public bool IsLeftEmpty()
3840
{
39-
return this.count == 0;
41+
return this.leftcount == 0;
4042
}
4143

4244
/// <summary>
43-
/// 返回队列中元素的数量
45+
/// 检查右侧栈是否为空
4446
/// </summary>
4547
/// <returns></returns>
46-
public int Size()
48+
public bool IsRightEmpty()
4749
{
48-
return this.count;
50+
return this.rightcount == 0;
51+
}
52+
53+
/// <summary>
54+
/// 返回左侧栈中元素的数量。
55+
/// </summary>
56+
/// <returns></returns>
57+
public int LeftSize()
58+
{
59+
return this.leftcount;
60+
}
61+
62+
/// <summary>
63+
/// 返回右侧栈中元素的数量。
64+
/// </summary>
65+
/// <returns></returns>
66+
public int RightSize()
67+
{
68+
return this.rightcount;
4969
}
5070

5171
/// <summary>
@@ -65,7 +85,11 @@ public void PushLeft(Item item)
6585
{
6686
this.last = this.first;
6787
}
68-
this.count++;
88+
else
89+
{
90+
oldFirst.prev = this.first;
91+
}
92+
this.leftcount++;
6993
}
7094

7195
/// <summary>
@@ -90,7 +114,7 @@ public void PushRight(Item item)
90114
{
91115
oldLast.next = this.last;
92116
}
93-
this.count++;
117+
this.rightcount++;
94118
}
95119

96120
/// <summary>
@@ -99,14 +123,14 @@ public void PushRight(Item item)
99123
/// <returns></returns>
100124
public Item PopRight()
101125
{
102-
if (IsEmpty())
126+
if (IsRightEmpty())
103127
{
104128
throw new InvalidOperationException();
105129
}
106130

107131
Item temp = this.last.item;
108132
this.last = this.last.prev;
109-
this.count--;
133+
this.rightcount--;
110134

111135
if (this.last == null)
112136
{
@@ -126,14 +150,14 @@ public Item PopRight()
126150
/// <returns></returns>
127151
public Item PopLeft()
128152
{
129-
if (IsEmpty())
153+
if (IsLeftEmpty())
130154
{
131155
throw new InvalidOperationException();
132156
}
133157

134158
Item temp = this.first.item;
135159
this.first = this.first.next;
136-
this.count--;
160+
this.leftcount--;
137161

138162
if (this.first == null)
139163
{

1 Fundamental/1.3/1.3.48/Program.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,25 @@ class Program
1818
{
1919
static void Main(string[] args)
2020
{
21+
DeStack<string> destack = new DeStack<string>();
22+
string input = "to be or not to - be - - that - - - is";
23+
string[] s = input.Split(' ');
2124

25+
foreach (string n in s)
26+
{
27+
if (!n.Equals("-"))
28+
destack.PushRight(n);
29+
else if (!destack.IsRightEmpty())
30+
Console.WriteLine(destack.PopRight());
31+
}
32+
33+
foreach (string n in s)
34+
{
35+
if (!n.Equals("-"))
36+
destack.PushLeft(n);
37+
else if (!destack.IsLeftEmpty())
38+
Console.WriteLine(destack.PopLeft());
39+
}
2240
}
2341
}
2442
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{48A26DF2-6699-44C3-B589-DAAFB7CD291F}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<RootNamespace>_1._3._49</RootNamespace>
10+
<AssemblyName>1.3.49</AssemblyName>
11+
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<PlatformTarget>AnyCPU</PlatformTarget>
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<PlatformTarget>AnyCPU</PlatformTarget>
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
29+
<OutputPath>bin\Release\</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
</PropertyGroup>
34+
<ItemGroup>
35+
<Reference Include="System" />
36+
<Reference Include="System.Core" />
37+
<Reference Include="System.Xml.Linq" />
38+
<Reference Include="System.Data.DataSetExtensions" />
39+
<Reference Include="Microsoft.CSharp" />
40+
<Reference Include="System.Data" />
41+
<Reference Include="System.Net.Http" />
42+
<Reference Include="System.Xml" />
43+
</ItemGroup>
44+
<ItemGroup>
45+
<Compile Include="Program.cs" />
46+
<Compile Include="Properties\AssemblyInfo.cs" />
47+
<Compile Include="StackQueue.cs" />
48+
</ItemGroup>
49+
<ItemGroup>
50+
<None Include="App.config" />
51+
</ItemGroup>
52+
<ItemGroup>
53+
<ProjectReference Include="..\Generics\Generics.csproj">
54+
<Project>{52b10c1b-78f7-493b-ab00-58efd921fda6}</Project>
55+
<Name>Generics</Name>
56+
</ProjectReference>
57+
</ItemGroup>
58+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
59+
</Project>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7" />
5+
</startup>
6+
</configuration>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace _1._3._49
8+
{
9+
class Program
10+
{
11+
static void Main(string[] args)
12+
{
13+
string input = "to be or not to - be - - that - - - is";
14+
string[] s = input.Split(' ');
15+
StackQueue<string> queue = new StackQueue<string>();
16+
17+
foreach (string n in s)
18+
{
19+
if (!n.Equals("-"))
20+
queue.Enqueue(n);
21+
else
22+
Console.WriteLine(queue.Dequeue());
23+
}
24+
}
25+
}
26+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// 有关程序集的一般信息由以下
6+
// 控制。更改这些特性值可修改
7+
// 与程序集关联的信息。
8+
[assembly: AssemblyTitle("1.3.49")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("1.3.49")]
13+
[assembly: AssemblyCopyright("Copyright © 2017")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// 将 ComVisible 设置为 false 会使此程序集中的类型
18+
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
19+
//请将此类型的 ComVisible 特性设置为 true。
20+
[assembly: ComVisible(false)]
21+
22+
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23+
[assembly: Guid("48a26df2-6699-44c3-b589-daafb7cd291f")]
24+
25+
// 程序集的版本信息由下列四个值组成:
26+
//
27+
// 主版本
28+
// 次版本
29+
// 生成号
30+
// 修订号
31+
//
32+
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
33+
// 方法是按如下所示使用“*”: :
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

0 commit comments

Comments
 (0)