Skip to content

Commit 80d82c3

Browse files
committed
1.3.48 Started
1 parent 8319fa4 commit 80d82c3

File tree

6 files changed

+324
-0
lines changed

6 files changed

+324
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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>{E1328906-04F4-4269-944A-F570E0884A4C}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<RootNamespace>_1._3._48</RootNamespace>
10+
<AssemblyName>1.3.48</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="Deque.cs" />
46+
<Compile Include="Program.cs" />
47+
<Compile Include="Properties\AssemblyInfo.cs" />
48+
</ItemGroup>
49+
<ItemGroup>
50+
<None Include="App.config" />
51+
</ItemGroup>
52+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
53+
</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>

1 Fundamental/1.3/1.3.48/Deque.cs

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace _1._3._48
9+
{
10+
public class Deque<Item> : IEnumerable<Item>
11+
{
12+
private class DoubleNode<T>
13+
{
14+
public T item;
15+
public DoubleNode<T> next;
16+
public DoubleNode<T> prev;
17+
}
18+
19+
DoubleNode<Item> first;
20+
DoubleNode<Item> last;
21+
int count;
22+
23+
/// <summary>
24+
/// 默认构造函数,建立一个双端队列。
25+
/// </summary>
26+
public Deque()
27+
{
28+
this.first = null;
29+
this.last = null;
30+
this.count = 0;
31+
}
32+
33+
/// <summary>
34+
/// 检查队列是否为空。
35+
/// </summary>
36+
/// <returns></returns>
37+
public bool IsEmpty()
38+
{
39+
return this.count == 0;
40+
}
41+
42+
/// <summary>
43+
/// 返回队列中元素的数量。
44+
/// </summary>
45+
/// <returns></returns>
46+
public int Size()
47+
{
48+
return this.count;
49+
}
50+
51+
/// <summary>
52+
/// 向左端添加一个元素。
53+
/// </summary>
54+
/// <param name="item">要添加的元素。</param>
55+
public void PushLeft(Item item)
56+
{
57+
DoubleNode<Item> oldFirst = this.first;
58+
this.first = new DoubleNode<Item>()
59+
{
60+
item = item,
61+
prev = null,
62+
next = oldFirst
63+
};
64+
if (oldFirst == null)
65+
{
66+
this.last = this.first;
67+
}
68+
this.count++;
69+
}
70+
71+
/// <summary>
72+
/// 向右端添加一个元素。
73+
/// </summary>
74+
/// <param name="item">要添加的元素。</param>
75+
public void PushRight(Item item)
76+
{
77+
DoubleNode<Item> oldLast = this.last;
78+
this.last = new DoubleNode<Item>()
79+
{
80+
item = item,
81+
prev = oldLast,
82+
next = null
83+
};
84+
85+
if (oldLast == null)
86+
{
87+
this.first = this.last;
88+
}
89+
else
90+
{
91+
oldLast.next = this.last;
92+
}
93+
this.count++;
94+
}
95+
96+
/// <summary>
97+
/// 从右端删除并返回一个元素。
98+
/// </summary>
99+
/// <returns></returns>
100+
public Item PopRight()
101+
{
102+
if (IsEmpty())
103+
{
104+
throw new InvalidOperationException();
105+
}
106+
107+
Item temp = this.last.item;
108+
this.last = this.last.prev;
109+
this.count--;
110+
111+
if (this.last == null)
112+
{
113+
this.first = null;
114+
}
115+
else
116+
{
117+
this.last.next.item = default(Item);
118+
this.last.next = null;
119+
}
120+
return temp;
121+
}
122+
123+
/// <summary>
124+
/// 从左端删除并返回一个元素。
125+
/// </summary>
126+
/// <returns></returns>
127+
public Item PopLeft()
128+
{
129+
if (IsEmpty())
130+
{
131+
throw new InvalidOperationException();
132+
}
133+
134+
Item temp = this.first.item;
135+
this.first = this.first.next;
136+
this.count--;
137+
138+
if (this.first == null)
139+
{
140+
this.last = null;
141+
}
142+
else
143+
{
144+
this.first.prev.item = default(Item);
145+
this.first.prev = null;
146+
}
147+
148+
return temp;
149+
}
150+
151+
public IEnumerator<Item> GetEnumerator()
152+
{
153+
return new DequeEnumerator(this.first);
154+
}
155+
156+
IEnumerator IEnumerable.GetEnumerator()
157+
{
158+
return GetEnumerator();
159+
}
160+
161+
private class DequeEnumerator : IEnumerator<Item>
162+
{
163+
private DoubleNode<Item> current;
164+
private DoubleNode<Item> first;
165+
166+
public DequeEnumerator(DoubleNode<Item> first)
167+
{
168+
this.current = new DoubleNode<Item>();
169+
this.current.next = first;
170+
this.current.prev = null;
171+
this.first = this.current;
172+
}
173+
174+
public Item Current => current.item;
175+
176+
object IEnumerator.Current => current.item;
177+
178+
public void Dispose()
179+
{
180+
this.current = null;
181+
this.first = null;
182+
}
183+
184+
public bool MoveNext()
185+
{
186+
if (this.current.next == null)
187+
return false;
188+
this.current = this.current.next;
189+
return true;
190+
}
191+
192+
public void Reset()
193+
{
194+
this.current = this.first;
195+
}
196+
}
197+
}
198+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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._48
8+
{
9+
/*
10+
* 1.3.48
11+
*
12+
* 双向队列与栈。
13+
* 用一个双向队列实现两个栈,保证每个栈操作只需要常数次的双向队列操作。
14+
* (请见练习 1.3.33)
15+
*
16+
*/
17+
class Program
18+
{
19+
static void Main(string[] args)
20+
{
21+
22+
}
23+
}
24+
}
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.48")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("1.3.48")]
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("e1328906-04f4-4269-944a-f570e0884a4c")]
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")]

Algorithms 4th Edition.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "1.3.46", "1 Fundamental\1.3
255255
EndProject
256256
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "1.3.47", "1 Fundamental\1.3\1.3.47\1.3.47.csproj", "{4FA8E7F0-87A7-4084-BA27-BA5DF4CE18A1}"
257257
EndProject
258+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "1.3.48", "1 Fundamental\1.3\1.3.48\1.3.48.csproj", "{E1328906-04F4-4269-944A-F570E0884A4C}"
259+
EndProject
258260
Global
259261
GlobalSection(SolutionConfigurationPlatforms) = preSolution
260262
Debug|Any CPU = Debug|Any CPU
@@ -697,6 +699,10 @@ Global
697699
{4FA8E7F0-87A7-4084-BA27-BA5DF4CE18A1}.Debug|Any CPU.Build.0 = Debug|Any CPU
698700
{4FA8E7F0-87A7-4084-BA27-BA5DF4CE18A1}.Release|Any CPU.ActiveCfg = Release|Any CPU
699701
{4FA8E7F0-87A7-4084-BA27-BA5DF4CE18A1}.Release|Any CPU.Build.0 = Release|Any CPU
702+
{E1328906-04F4-4269-944A-F570E0884A4C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
703+
{E1328906-04F4-4269-944A-F570E0884A4C}.Debug|Any CPU.Build.0 = Debug|Any CPU
704+
{E1328906-04F4-4269-944A-F570E0884A4C}.Release|Any CPU.ActiveCfg = Release|Any CPU
705+
{E1328906-04F4-4269-944A-F570E0884A4C}.Release|Any CPU.Build.0 = Release|Any CPU
700706
EndGlobalSection
701707
GlobalSection(SolutionProperties) = preSolution
702708
HideSolutionNode = FALSE
@@ -824,5 +830,6 @@ Global
824830
{E4B3F7BE-0F12-480F-BC40-B6A213C52AC7} = {24B47AC3-0399-41CA-B90D-50BC6C56D919}
825831
{C5FBF10A-8FD5-42AB-BFB1-5012F3FEE320} = {24B47AC3-0399-41CA-B90D-50BC6C56D919}
826832
{4FA8E7F0-87A7-4084-BA27-BA5DF4CE18A1} = {24B47AC3-0399-41CA-B90D-50BC6C56D919}
833+
{E1328906-04F4-4269-944A-F570E0884A4C} = {24B47AC3-0399-41CA-B90D-50BC6C56D919}
827834
EndGlobalSection
828835
EndGlobal

0 commit comments

Comments
 (0)