idk why these stuffs get stashed for so long and I didn't ever commit them

This commit is contained in:
2025-11-06 09:43:54 +08:00
parent 5dbdfef1a1
commit e01c041259
232 changed files with 22806 additions and 1256 deletions

Binary file not shown.

View File

@@ -0,0 +1,54 @@
#include <string>
#include <iostream>
using namespace std;
#include "LinkStack.h"
bool match(string exp)
{
SNode<char>* S;
InitStack(S);
int flag = 1, i = 0;
char ch, e, x;
ch = exp[i++];
while (ch != '#' && flag)
{
switch (ch)
{
case '[':
case '(':
cout << "左括号进栈!" << endl;
Push(S, ch);
break;
case ')':
GetTop(S, e);
if (!StackEmpty(S) && e == '(')
{
Pop(S, x);
cout << "右括号出栈!" << endl;
}
else flag = 0;
break;
case ']':
GetTop(S, e);
if (!StackEmpty(S) && e == '[') Pop(S, x);
else flag = 0;
break;
}
ch = exp[i++];
}
if (StackEmpty(S) && flag) return true;
else return false;
}
int main()
{
int flag;
string exp;
cout << "请输入待匹配的表达式,以“#”结束:" << endl;
cin >> exp;
flag = match(exp);
if (flag) cout << "括号匹配成功!" << endl;
else cout << "括号匹配失败!" << endl;
return 0;
}

View File

@@ -0,0 +1,31 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34728.123
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BracketsMatch", "BracketsMatch.vcxproj", "{BC507152-80AB-4A4F-9006-339728D357CA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BC507152-80AB-4A4F-9006-339728D357CA}.Debug|x64.ActiveCfg = Debug|x64
{BC507152-80AB-4A4F-9006-339728D357CA}.Debug|x64.Build.0 = Debug|x64
{BC507152-80AB-4A4F-9006-339728D357CA}.Debug|x86.ActiveCfg = Debug|Win32
{BC507152-80AB-4A4F-9006-339728D357CA}.Debug|x86.Build.0 = Debug|Win32
{BC507152-80AB-4A4F-9006-339728D357CA}.Release|x64.ActiveCfg = Release|x64
{BC507152-80AB-4A4F-9006-339728D357CA}.Release|x64.Build.0 = Release|x64
{BC507152-80AB-4A4F-9006-339728D357CA}.Release|x86.ActiveCfg = Release|Win32
{BC507152-80AB-4A4F-9006-339728D357CA}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {12C9DCB1-398A-4F5B-9896-2020AF51DA75}
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,138 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{bc507152-80ab-4a4f-9006-339728d357ca}</ProjectGuid>
<RootNamespace>BracketsMatch</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="LinkStack.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="BracketsMatch.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="源文件">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="头文件">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="资源文件">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="LinkStack.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="BracketsMatch.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,92 @@
template <class DT>
struct SNode //结点
{
DT data; //数据域,存储数据元素值
SNode* next;//指针域,指向下一个结点
};
//【算法3.6】
template <class DT>
void InitStack(SNode<DT>*& S)//创建空链栈
{
S = NULL;
}
//【算法3.7】
template <class DT>
void DestroyStack(SNode<DT>* (&S))//释放链栈
{
SNode<DT>* p;
while (S)//从头结点开始,依次释放结点
{
p = S;
S = S->next;
delete p;
}
//L=NULL;//头结点指向空
}
//【算法3.8】
template<class DT>
bool Push(SNode<DT>*& S, DT e)
{
SNode<DT>* p;
p = new SNode<DT>;
if (!p) return false; //创建失败,结束运行
p->data = e; // 新结点赋值
p->next = S; //结点S链接到p结点之后
S = p;
return true; // 插入成功返回true
}
//【算法3.9】
template<class DT>
bool Pop(SNode<DT>*& S, DT& e)
{
SNode<DT>* p;
if (S == NULL) return false;
p = S;
e = p->data;
S = S->next;
delete p;
return true; // 删除成功返回true
}
//【算法3.10】
template<class DT>
bool GetTop(SNode<DT>* S, DT& e)
{
SNode<DT>* p;
if (S == NULL) return false;
p = S;
e = p->data;
return true; // 删除成功返回true
}
//测栈空
template<class DT>
bool StackEmpty(SNode<DT>* S)
{
if (S == NULL)
return true;
else
return false;
}
//显示栈内容
template<class DT>
void DispStack(SNode<DT>* S)
{
SNode<DT>* p;
p = S;
while (p)
{
cout << p->data << "\t";
p = p->next;
}
cout << endl;
}

View File

@@ -0,0 +1,77 @@
#include <iostream>
#include "LinkQueue.h"
using namespace std;
struct Car
{
int no; //车号
char type; //c:客车t:货车
};
//求队列长度
template<class DT>
int QueueLength(LinkQueue<DT> Q)
{
int n = 0;
QNode<DT>* p = Q.front->next;
while (p)
{
p = p->next;
n++;
}
return n;
}
//车辆入队
void Ferry(LinkQueue<Car>& Qc, LinkQueue<Car>& Qt)
{
int i = 0;
Car e;
while (QueueLength(Qc) + QueueLength(Qt) > 0) //队列非空
{
if (QueueLength(Qc) > 0) //客车队列非空
{
while ((i < 4) && (QueueLength(Qc) > 0)) //客车数小于4且客车队列非空
{
DeQueue(Qc, e); //客车出队
cout << "车号:" << e.no << "\t类型:" << e.type << endl;
i++;
}
i = 0;
}
if (QueueLength(Qt) > 0) //货车队列非空
{
DeQueue(Qt, e); //货车出队
cout << "车号:" << e.no << "\t类型:" << e.type << endl;
}
}
cout << "所有车辆已过江!" << endl;
}
int main()
{
LinkQueue<Car> Qc, Qt;
Car e;
int i, n;
InitQueue(Qc);
InitQueue(Qt);
cout << "客车数:";
cin >> n;
for (i = 1; i <= n; i++) //客车入队
{
e.no = i;
e.type = 'c';
EnQueue(Qc, e);
}
cout << "货车数:";
cin >> n;
for (i = 1; i <= n; i++) //货车入队
{
e.no = i;
e.type = 't';
EnQueue(Qt, e);
}
Ferry(Qc, Qt); //车辆过江
DestroyQueue(Qc);
DestroyQueue(Qt);
return 0;
}

View File

@@ -0,0 +1,31 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34728.123
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Ferry", "Ferry.vcxproj", "{DFE075CA-094D-4856-92A8-0461FC180B13}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{DFE075CA-094D-4856-92A8-0461FC180B13}.Debug|x64.ActiveCfg = Debug|x64
{DFE075CA-094D-4856-92A8-0461FC180B13}.Debug|x64.Build.0 = Debug|x64
{DFE075CA-094D-4856-92A8-0461FC180B13}.Debug|x86.ActiveCfg = Debug|Win32
{DFE075CA-094D-4856-92A8-0461FC180B13}.Debug|x86.Build.0 = Debug|Win32
{DFE075CA-094D-4856-92A8-0461FC180B13}.Release|x64.ActiveCfg = Release|x64
{DFE075CA-094D-4856-92A8-0461FC180B13}.Release|x64.Build.0 = Release|x64
{DFE075CA-094D-4856-92A8-0461FC180B13}.Release|x86.ActiveCfg = Release|Win32
{DFE075CA-094D-4856-92A8-0461FC180B13}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B24F9342-2DAA-4663-8993-00F01D577229}
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,138 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{dfe075ca-094d-4856-92a8-0461fc180b13}</ProjectGuid>
<RootNamespace>Ferry</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="LinkQueue.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="Ferry.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="源文件">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="头文件">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="资源文件">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="LinkQueue.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Ferry.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,129 @@
#include <iostream>
using namespace std;
template <class DT>
struct QNode //结点
{
DT data; //数据域,存储数据元素值
QNode* next;//指针域,指向下一个结点
};
template<class DT>
struct LinkQueue
{
QNode<DT>* front;
QNode<DT>* rear;
};
//【算法3.19】
template <class DT>
void InitQueue(LinkQueue<DT>& Q)//创建空队列
{
Q.front = new QNode<DT>; //创建头结点
if (!Q.front) exit(1); //创建失败,结束运行
Q.front->next = NULL;
Q.rear = Q.front;
}
//【算法3.20】
template <class DT>
void DestroyQueue(LinkQueue<DT>& Q)//释放链队
{
QNode<DT>* p;
while (Q.front)//从头结点开始,依次释放结点
{
p = Q.front;
Q.front = Q.front->next;
delete p;
}
Q.rear = Q.front = NULL;
}
template <class DT>
void ClearQueue(LinkQueue<DT>& Q) // 清空链队
{
QNode<DT>* p;
while (Q.front->next) //从队头开始,依次释放结点
{
p = Q.front->next;
Q.front->next = p->next;
delete p;
}
Q.front->next = NULL; // 空队
Q.rear = Q.front;
}
//【算法3.21】 入队
template<class DT>
bool EnQueue(LinkQueue<DT>& Q, DT e)
{
QNode<DT>* p;
p = new QNode<DT>; // 创建新结点
if (!p) return false; // 创建失败,结束运行
p->data = e; // 新结点赋值
p->next = NULL; // 链在队尾
Q.rear->next = p;
Q.rear = p;
return true; // 入队成功返回true
}
//【算法3.22】 出队
template<class DT>
bool DeQueue(LinkQueue<DT>& Q, DT& e)
{
QNode<DT>* p;
if (Q.front == Q.rear) return false; //队空返回false
p = Q.front->next; // 取出队元素
e = p->data;
Q.front->next = p->next; //队首元素出队
if (Q.rear == p) //只有一个元素时出队,
Q.rear = Q.front; // 修改队尾
delete p;
return true; // 出队成功返回true
}
//【算法3.23】 取队头元素
template<class DT>
bool GetHead(LinkQueue<DT> Q, DT& e)
{
if (Q.front == Q.rear) return false; // 队空返回false
e = Q.front->next->data;
return true; // 删除成功返回true
}
//取队尾元素
template<class DT>
bool GetTail(LinkQueue<DT> Q, DT& e)
{
if (Q.front == Q.rear) // 队空
return false; // 返回false
e = Q.rear->data; // 获取队尾元素
return true; // 返回true
}
//测队空
template<class DT>
bool QueueEmpty(LinkQueue<DT> Q)
{
if (Q.front == Q.rear) // 队空
return true; //返回true
else //非空
return false; //返回false
}
//显示队列内容
template<class DT>
void DispQueue(LinkQueue<DT> Q)
{
QNode<DT>* p;
p = Q.front->next;
while (p)
{
cout << p->data << "\t";
p = p->next;
}
cout << endl;
}