Skip to content

Commit 3c9566d

Browse files
1992219922
authored andcommitted
添加项目文件。
1 parent 1e4a1f8 commit 3c9566d

File tree

6 files changed

+393
-0
lines changed

6 files changed

+393
-0
lines changed

DoubleStack.c

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#include<stdio.h>
2+
#include<stdlib.h>
3+
#define error 0
4+
#define ok 1
5+
#define MAXSIZE 20
6+
typedef int Status;
7+
typedef int SElemtype;
8+
typedef struct
9+
{
10+
SElemtype data[MAXSIZE];
11+
int top1;
12+
int top2;
13+
}SqDoubleStack;
14+
Status InitStack(SqDoubleStack* S)
15+
{
16+
S->top1 = -1;
17+
S->top2 = MAXSIZE - 1;
18+
return ok;
19+
}
20+
Status Push(SqDoubleStack* S, SElemtype e, int StackNumber)
21+
{
22+
if (S->top1 + 1 == S->top2)
23+
return error;
24+
if (StackNumber == 1)
25+
S->data[++S->top1] = e;
26+
else if (StackNumber == 2)
27+
S->data[--S->top2] = e;
28+
return ok;
29+
}
30+
Status visit(SElemtype j)
31+
{
32+
printf("%d ", j);
33+
return ok;
34+
}
35+
Status StackTraverse(SqDoubleStack S)
36+
{
37+
int j = 0;
38+
while (j <= S.top1)
39+
{
40+
visit(S.data[j++]);
41+
}
42+
j = S.top2;
43+
while (j < MAXSIZE-1)
44+
{
45+
visit(S.data[j++]);
46+
}
47+
printf("\n");
48+
return ok;
49+
}
50+
Status StackLength(SqDoubleStack S)
51+
{
52+
return(S.top1 + 1) + (MAXSIZE - S.top2);
53+
}
54+
Status Pop(SqDoubleStack* S, SElemtype* e,int StackNumber)
55+
{
56+
if (S->top1 == -1 || S->top2 == MAXSIZE - 1)
57+
return error;
58+
if (StackNumber == 1)
59+
*e = S->data[S->top1--];
60+
else if (StackNumber == 2)
61+
*e = S->data[S->top2++];
62+
return ok;
63+
}
64+
Status StackEmpty(SqDoubleStack S)
65+
{
66+
if (S.top1 == -1 && S.top2 == MAXSIZE)
67+
return ok;
68+
else
69+
return error;
70+
}
71+
Status ClearStack(SqDoubleStack* S)
72+
{
73+
S->top1 = -1;
74+
S->top2 = MAXSIZE ;
75+
return ok;
76+
}
77+
int main()
78+
{
79+
int i, e;
80+
SqDoubleStack S;
81+
if (InitStack(&S) == ok)
82+
{
83+
for (int i = 1; i <= 5; i++)
84+
Push(&S, i, 1);
85+
for (i = MAXSIZE; i >= MAXSIZE - 2; i--)
86+
Push(&S, i, 2);
87+
}
88+
printf("栈中的元素依次为:");
89+
StackTraverse(S);
90+
printf("当前栈中元素有:%d \n", StackLength(S));
91+
Pop(&S, &e, 2);
92+
printf("弹出的栈顶元素 e=%d\n", e);
93+
printf("栈中的元素依次为:");
94+
StackTraverse(S);
95+
printf("栈空否:%d(1:是 0:否)\n", StackEmpty(S));
96+
for (int j = 6; j <= MAXSIZE - 2; j++)
97+
Push(&S, j, 1);
98+
printf("栈中元素依次为:");
99+
StackTraverse(S);
100+
printf("栈满否:%d(1:否 0:满)\n", Push(&S, 100, 1));
101+
ClearStack(&S);
102+
printf("清空栈后,栈空否:%d(1:是 0:否)\n", StackEmpty(S));
103+
return 0;
104+
105+
}

LinkStack.c

Whitespace-only changes.

SqStack.c

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
//#include<stdio.h>
2+
//#include<stdlib.h>
3+
//#define MAXSIZE 100
4+
//#define error 0
5+
//#define ok 1
6+
//typedef int SElemtype;
7+
//typedef int Status;
8+
//typedef struct
9+
//{
10+
// SElemtype data[MAXSIZE];
11+
// int top;
12+
//}SqStack;
13+
//
14+
//Status InitStack(SqStack* S)
15+
//{
16+
// /*S->data = (SElemtype*)malloc(MAXSIZE * sizeof(SElemtype));*/
17+
// S->top = -1;
18+
// return ok;
19+
//}
20+
//Status Push(SqStack* S, SElemtype e)
21+
//{
22+
// if (S->top == MAXSIZE - 1)
23+
// return error;
24+
// S->top++;
25+
// S->data[S->top] = e;
26+
// return ok;
27+
//}
28+
//Status visit(SElemtype c)
29+
//{
30+
// printf("%d ", c);
31+
// return ok;
32+
//}
33+
//Status StackTraverse(SqStack S)
34+
//{
35+
// int i=0;
36+
// while (i<=S.top)
37+
// {
38+
// visit(S.data[i++]);
39+
// }
40+
// printf("\n");
41+
// return ok;
42+
//}
43+
//Status Pop(SqStack * S, SElemtype* e)
44+
//{
45+
// if (S->top == -1)
46+
// return error;
47+
// *e = S->data[S->top];
48+
// S->top--;
49+
//}
50+
//Status StackEmpty(SqStack S)
51+
//{
52+
// if (S.top == -1)
53+
// return ok;
54+
// else
55+
// return error;
56+
//}
57+
//Status GetTop(SqStack S, SElemtype* e)
58+
//{
59+
// *e = S.data[S.top];
60+
// return ok;
61+
//}
62+
//Status StackLength(SqStack S)
63+
//{
64+
// return S.top + 1;
65+
//}
66+
//Status ClearStack(SqStack* S)
67+
//{
68+
// S->top = -1;
69+
// return ok;
70+
//}
71+
//int main()
72+
//{
73+
// int i,e;
74+
// SqStack S;
75+
// if(InitStack(&S)==ok)
76+
// for (i = 0; i < 10; i++)
77+
// {
78+
// Push(&S,i);
79+
// }
80+
// printf("插入后的元素:\n");
81+
// StackTraverse(S);
82+
// Pop(&S, &e);
83+
// printf("弹出栈顶元素 e=%d\n", e);
84+
// printf("栈是否为空 :%d(1:空 0:否)\n", StackEmpty(S));
85+
// StackTraverse(S);
86+
// GetTop(S, &e);
87+
// printf("现在栈顶元素为%d\n", e);
88+
// printf("栈的长度为 %d\n", StackLength(S));
89+
// ClearStack(&S);
90+
// printf("栈是否为空 :%d(1:空 0:否)\n", StackEmpty(S));
91+
// return 0;
92+
//}

Stack.sln

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.5.33530.505
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Stack", "Stack.vcxproj", "{BA92ABC4-01E8-40AC-A718-D9054373064A}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x64 = Debug|x64
11+
Debug|x86 = Debug|x86
12+
Release|x64 = Release|x64
13+
Release|x86 = Release|x86
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{BA92ABC4-01E8-40AC-A718-D9054373064A}.Debug|x64.ActiveCfg = Debug|x64
17+
{BA92ABC4-01E8-40AC-A718-D9054373064A}.Debug|x64.Build.0 = Debug|x64
18+
{BA92ABC4-01E8-40AC-A718-D9054373064A}.Debug|x86.ActiveCfg = Debug|Win32
19+
{BA92ABC4-01E8-40AC-A718-D9054373064A}.Debug|x86.Build.0 = Debug|Win32
20+
{BA92ABC4-01E8-40AC-A718-D9054373064A}.Release|x64.ActiveCfg = Release|x64
21+
{BA92ABC4-01E8-40AC-A718-D9054373064A}.Release|x64.Build.0 = Release|x64
22+
{BA92ABC4-01E8-40AC-A718-D9054373064A}.Release|x86.ActiveCfg = Release|Win32
23+
{BA92ABC4-01E8-40AC-A718-D9054373064A}.Release|x86.Build.0 = Release|Win32
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {341AAA22-CF49-4012-B0E1-0B3165BC0D26}
30+
EndGlobalSection
31+
EndGlobal

Stack.vcxproj

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<PropertyGroup Label="Globals">
22+
<VCProjectVersion>16.0</VCProjectVersion>
23+
<Keyword>Win32Proj</Keyword>
24+
<ProjectGuid>{ba92abc4-01e8-40ac-a718-d9054373064a}</ProjectGuid>
25+
<RootNamespace>Stack</RootNamespace>
26+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
27+
</PropertyGroup>
28+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
29+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
30+
<ConfigurationType>Application</ConfigurationType>
31+
<UseDebugLibraries>true</UseDebugLibraries>
32+
<PlatformToolset>v143</PlatformToolset>
33+
<CharacterSet>Unicode</CharacterSet>
34+
</PropertyGroup>
35+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
36+
<ConfigurationType>Application</ConfigurationType>
37+
<UseDebugLibraries>false</UseDebugLibraries>
38+
<PlatformToolset>v143</PlatformToolset>
39+
<WholeProgramOptimization>true</WholeProgramOptimization>
40+
<CharacterSet>Unicode</CharacterSet>
41+
</PropertyGroup>
42+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
43+
<ConfigurationType>Application</ConfigurationType>
44+
<UseDebugLibraries>true</UseDebugLibraries>
45+
<PlatformToolset>v143</PlatformToolset>
46+
<CharacterSet>Unicode</CharacterSet>
47+
</PropertyGroup>
48+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
49+
<ConfigurationType>Application</ConfigurationType>
50+
<UseDebugLibraries>false</UseDebugLibraries>
51+
<PlatformToolset>v143</PlatformToolset>
52+
<WholeProgramOptimization>true</WholeProgramOptimization>
53+
<CharacterSet>Unicode</CharacterSet>
54+
</PropertyGroup>
55+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
56+
<ImportGroup Label="ExtensionSettings">
57+
</ImportGroup>
58+
<ImportGroup Label="Shared">
59+
</ImportGroup>
60+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
61+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
62+
</ImportGroup>
63+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
64+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
65+
</ImportGroup>
66+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
67+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
68+
</ImportGroup>
69+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
70+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
71+
</ImportGroup>
72+
<PropertyGroup Label="UserMacros" />
73+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
74+
<ClCompile>
75+
<WarningLevel>Level3</WarningLevel>
76+
<SDLCheck>true</SDLCheck>
77+
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
78+
<ConformanceMode>true</ConformanceMode>
79+
</ClCompile>
80+
<Link>
81+
<SubSystem>Console</SubSystem>
82+
<GenerateDebugInformation>true</GenerateDebugInformation>
83+
</Link>
84+
</ItemDefinitionGroup>
85+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
86+
<ClCompile>
87+
<WarningLevel>Level3</WarningLevel>
88+
<FunctionLevelLinking>true</FunctionLevelLinking>
89+
<IntrinsicFunctions>true</IntrinsicFunctions>
90+
<SDLCheck>true</SDLCheck>
91+
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
92+
<ConformanceMode>true</ConformanceMode>
93+
</ClCompile>
94+
<Link>
95+
<SubSystem>Console</SubSystem>
96+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
97+
<OptimizeReferences>true</OptimizeReferences>
98+
<GenerateDebugInformation>true</GenerateDebugInformation>
99+
</Link>
100+
</ItemDefinitionGroup>
101+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
102+
<ClCompile>
103+
<WarningLevel>Level3</WarningLevel>
104+
<SDLCheck>true</SDLCheck>
105+
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
106+
<ConformanceMode>true</ConformanceMode>
107+
</ClCompile>
108+
<Link>
109+
<SubSystem>Console</SubSystem>
110+
<GenerateDebugInformation>true</GenerateDebugInformation>
111+
</Link>
112+
</ItemDefinitionGroup>
113+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
114+
<ClCompile>
115+
<WarningLevel>Level3</WarningLevel>
116+
<FunctionLevelLinking>true</FunctionLevelLinking>
117+
<IntrinsicFunctions>true</IntrinsicFunctions>
118+
<SDLCheck>true</SDLCheck>
119+
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
120+
<ConformanceMode>true</ConformanceMode>
121+
</ClCompile>
122+
<Link>
123+
<SubSystem>Console</SubSystem>
124+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
125+
<OptimizeReferences>true</OptimizeReferences>
126+
<GenerateDebugInformation>true</GenerateDebugInformation>
127+
</Link>
128+
</ItemDefinitionGroup>
129+
<ItemGroup>
130+
<ClCompile Include="DoubleStack.c" />
131+
<ClCompile Include="LinkStack.c" />
132+
<ClCompile Include="SqStack.c" />
133+
</ItemGroup>
134+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
135+
<ImportGroup Label="ExtensionTargets">
136+
</ImportGroup>
137+
</Project>

0 commit comments

Comments
 (0)