8000 Merge branch 'master' of https://github.com/tthhee/xiangyu · tthhee/leetcode@32b4471 · GitHub
[go: up one dir, main page]

Skip to content

Commit 32b4471

Browse files
committed
Merge branch 'master' of https://github.com/tthhee/xiangyu
2 parents 9850cf8 + 3d0cc15 commit 32b4471

33 files changed

+219
-80
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
#v4.0:v100
2-
Debug|Win32|E:\Git Repository\Data Structures and Algorithm Analysis in C\List_Sample\|
1+
#v4.0:v100:false
2+
Debug|Win32|F:\Git Repository\xiangyu\Data Structures and Algorithm Analysis in C\List_Sample\|
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,37 @@
1-
生成启动时间为 2015/1/27 0:44:01
2-
1>项目“E:\Git Repository\Data Structures and Algorithm Analysis in C\List_Sample\List_Sample\List_Sample.vcxproj”在节点 2 上(build 个目标)。
1+
生成启动时间为 2015/1/28 11:16:03
2+
1>项目“F:\Git Repository\xiangyu\Data Structures and Algorithm Analysis in C\List_Sample\List_Sample\List_Sample.vcxproj”在节点 2 上(build 个目标)。
33
1>InitializeBuildStatus:
44
正在创建“Debug\List_Sample.unsuccessfulbuild”,因为已指定“AlwaysCreate”。
55
ClCompile:
6-
所有输出均为最新。
6+
d:\Visual Studio 2010\VC\bin\CL.exe /c /ZI /nologo /W3 /WX- /Od /Oy- /D WIN32 /D _DEBUG /D _CONSOLE /D _UNICODE /D UNICODE /Gm /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Fo"Debug\\" /Fd"Debug\vc100.pdb" /Gd /TC /analyze- /errorReport:prompt List_Sample.c Main.c
7+
Main.c
8+
List_Sample.c
9+
1>f:\git repository\xiangyu\data structures and algorithm analysis in c\list_sample\list_sample\list_sample.c(405): warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
10+
d:\visual studio 2010\vc\include\stdio.h(304) : 参见“scanf”的声明
11+
1>f:\git repository\xiangyu\data structures and algorithm analysis in c\list_sample\list_sample\list_sample.c(417): warning C4101: “LPos”: 未引用的局部变量
12+
1>f:\git repository\xiangyu\data structures and algorithm analysis in c\list_sample\list_sample\list_sample.c(418): warning C4101: “i”: 未引用的局部变量
13+
1>f:\git repository\xiangyu\data structures and algorithm analysis in c\list_sample\list_sample\list_sample.c(417): warning C4101: “ResultPos”: 未引用的局部变量
14+
1>f:\git repository\xiangyu\data structures and algorithm analysis in c\list_sample\list_sample\list_sample.c(418): warning C4101: “j”: 未引用的局部变量
15+
正在生成代码...
16+
1>f:\git repository\xiangyu\data structures and algorithm analysis in c\list_sample\list_sample\list_sample.c(421): warning C4716: “PolynominalExp”: 必须返回一个值
717
ManifestResourceCompile:
818
所有输出均为最新。
919
Link:
10-
所有输出均为最新。
20+
d:\Visual Studio 2010\VC\bin\link.exe /ERRORREPORT:PROMPT /OUT:"F:\Git Repository\xiangyu\Data Structures and Algorithm Analysis in C\List_Sample\Debug\List_Sample.exe" /INCREMENTAL /NOLOGO opencv_ml249d.lib opencv_calib3d249d.lib opencv_contrib249d.lib opencv_core249d.lib opencv_features2d249d.lib opencv_flann249d.lib opencv_gpu249d.lib opencv_highgui249d.lib opencv_imgproc249d.lib opencv_legacy249d.lib opencv_objdetect249d.lib opencv_ts249d.lib opencv_video249d.lib opencv_nonfree249d.lib opencv_ocl249d.lib opencv_photo249d.lib opencv_stitching249d.lib opencv_superres249d.lib opencv_videostab249d.lib opencv_objdetect249.lib opencv_ts249.lib opencv_video249.lib opencv_nonfree249.lib opencv_ocl249.lib opencv_photo249.lib opencv_stitching249.lib opencv_superres249.lib opencv_videostab249.lib opencv_calib3d249.lib opencv_contrib249.lib opencv_core249.lib opencv_features2d249.lib opencv_flann249.lib opencv_gpu249.lib opencv_highgui249.lib opencv_imgproc249.lib opencv_legacy249.lib opencv_ml249.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /ManifestFile:"Debug\List_Sample.exe.intermediate.manifest" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"F:\Git Repository\xiangyu\Data Structures and Algorithm Analysis in C\List_Sample\Debug\List_Sample.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"F:\Git Repository\xiangyu\Data Structures and Algorithm Analysis in C\List_Sample\Debug\List_Sample.lib" /MACHINE:X86 Debug\List_Sample.exe.embed.manifest.res
21+
Debug\List_Sample.obj
22+
Debug\Main.obj
23+
Debug\stack.obj
1124
Manifest:
25+
C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\mt.exe /nologo /verbose /out:"Debug\List_Sample.exe.embed.manifest" /manifest Debug\List_Sample.exe.intermediate.manifest
26+
所有输出均为最新。
27+
LinkEmbedManifest:
1228
所有输出均为最新。
29+
List_Sample.vcxproj -> F:\Git Repository\xiangyu\Data Structures and Algorithm Analysis in C\List_Sample\Debug\List_Sample.exe
1330
FinalizeBuildStatus:
1431
正在删除文件“Debug\List_Sample.unsuccessfulbuild”。
1532
正在对“Debug\List_Sample.lastbuildstate”执行 Touch 任务。
16-
1>已完成生成项目“E:\Git Repository\Data Structures and Algorithm Analysis in C\List_Sample\List_Sample\List_Sample.vcxproj”(build 个目标)的操作。
33+
1>已完成生成项目“F 10000 :\Git Repository\xiangyu\Data Structures and Algorithm Analysis in C\List_Sample\List_Sample\List_Sample.vcxproj”(build 个目标)的操作。
1734

1835
生成成功。
1936

20-
已用时间 00:00:00.08
37+
已用时间 00:00:01.70
Binary file not shown.

Data Structures and Algorithm Analysis in C/List_Sample/List_Sample/List_Sample.c

+81-64
Original file line numberDiff line numberDiff line change
@@ -290,37 +290,7 @@ void Sort(List L)
290290
Q = Q->Next;
291291
}
292292
}
293-
/*
294-
List Intersect(List L, List P)
295-
{
296-
List temp1, temp2, temp;
297-
List head;
298-
head = L;
299-
temp1 = L->Next;
300-
temp2 = P->Next;
301-
while(temp1 != NULL && temp2 != NULL)
302-
{
303-
if(temp1->Element != temp2->Element)
304-
{
305-
temp = temp1->Next;
306-
temp2 = temp2->Next;
307-
Delete(temp1->Element, L);
308-
// if(temp != NULL)
309-
temp1 = temp;
310-
}
311-
else
312-
{
313-
temp1 = temp1->Next;
314-
temp2 = temp2->Next;
315-
}
316-
if(temp2 == NULL)
317-
{
318-
temp1 = NULL;
319-
}
320-
}
321-
return head;
322-
}
323-
*/
293+
324294
Position First(List L)
325295
{
326296
if(L->Next==NULL)
@@ -333,13 +303,13 @@ Position Header(List L)
333303
{
334304
return L;
335305
}
336-
void Intersect(List L1, List L2, List Result)
306+
List Intersect(List L1, List L2)
337307
{
338-
// List Result;
308+
List Result;
339309
Position L1Pos, L2Pos, ResultPos;
340310
L1Pos = First(L1);
341311
L2Pos = First(L2);
342-
// Result = MakeEmpty(Result);
312+
Result =InitEmpty();
343313
ResultPos = Result;
344314
while(L1Pos!=NULL && L2Pos!=NULL)
345315
{
@@ -359,46 +329,93 @@ void Intersect(List L1, List L2, List Result)
359329
L2Pos = L2Pos->Next;
360330
}
361331
}
362-
// return Result;
332+
return Result;
363333
}
334+
/*************************************************
335+
Description:
336+
Union()求两个链表L1, L2元素的并集。(注意:这里两个链表的元素必须是经过从小到大排序的)
337+
函数返回并集结果。
338+
注意:函数中的 ResultPos = Result;因为插入Insert()函数是在Pos位置的后面插入,所以对于一个空链表
339+
要想将元素插入到第一个位置,则Pos应为链表的head.
340+
**************************************************/
364341
List Union(List L1, List L2)
365342
{
366-
// List Result;
367-
List temp , temp2;
368-
List intersect;
369-
intersect = InitEmpty();
370-
Intersect(L1, L2, intersect);
371-
// Result = L1;
372-
// temp = L2->Next;
373-
temp2 = intersect->Next;
374-
while(temp2 != NULL)
343+
List Result;
344+
ElementType ResultElement;
345+
List L1Pos, L2Pos, ResultPos;
346+
Result = InitEmpty();
347+
L1Pos = L1->Next;
348+
L2Pos = L2->Next;
349+
ResultPos = Result;
350+
while(L1Pos != NULL && L2Pos != NULL)
375351
{
376-
temp = L2->Next;
377-
while(temp != NULL)
352+
if(L1Pos->Element < L2Pos->Element)
378353
{
379-
if(temp->Element == temp2->Element)
380-
{
381-
Delete(temp2->Element, L2);
382-
}
383-
temp = temp->Next;
384-
354+
ResultElement = L1Pos->Element;
355+
L1Pos = L1Pos->Next;
356+
}
357+
else if(L2Pos->Element < L1Pos->Element)
358+
{
359+
ResultElement = L2Pos->Element;
360+
L2Pos = L2Pos->Next;
385361
}
362+
else
363+
{
364+
ResultElement = L1Pos->Element;
365+
L1Pos = L1Pos->Next;
366+
L2Pos = L2Pos->Next;
386367

387-
// temp = temp->Next;
388-
temp2 = temp2->Next;
368+
}
369+
Insert(ResultElement, Result, ResultPos);
370+
ResultPos = ResultPos->Next;
389371
}
390-
temp = L1;
391-
while(temp->Next != NULL)
372+
while(L1Pos != NULL)
392373
{
393-
temp = temp->Next;
374+
Insert(L1Pos->Element, Result, ResultPos);
375+
L1Pos = L1Pos->Next;
376+
ResultPos = ResultPos->Next;
394377
}
395-
temp2 = temp;
396-
temp = L2->Next;
397-
while(temp != NULL)
378+
while(L2Pos != NULL)
398379
{
399-
Insert(temp->Element, L1, temp2);
400-
temp = temp->Next;
401-
temp2 = temp2->Next;
380+
Insert(L2Pos->Element, Result, ResultPos);
381+
L2Pos = L2Pos->Next;
382+
ResultPos = ResultPos->Next;
402383
}
403-
return L1;
384+
return Result;
385+
}
386+
387+
/************************************************
388+
Description:
389+
输入n次多项式,按照次数从低到高依次输入各项系数
390+
系数存储在链表中
391+
*************************************************/
392+
List Polynominal(int n)
393+
{
394+
List L;
395+
List LPos;
396+
int a;
397+
int i;
398+
L = InitEmpty();
399+
LPos = L;
400+
printf("%d次多项式各项系数:\n", n);
401+
for(i=0; i<=n; i++)
402+
{
403+
404+
printf("%d次项系数: ", i);
405+
scanf("%d", &a);
406+
Insert(a,L,LPos);
407+
}
408+
return L;
409+
}
410+
/*****************************************
411+
Description:
412+
未实现
413+
*****************************************/
414+
List PolynominalExp(List L, int n, int p)
415+
{
416+
List Result;
417+
List LPos, ResultPos;
418+
int i, j;
419+
Result = InitEmpty();
420+
404421
}

Data Structures and Algorithm Analysis in C/List_Sample/List_Sample/List_Sample.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ void PrintLots(List L, List P);
2525
void ExchangeElement_WithNext(ElementType x, List L);
2626
void ExchangePosition_WithNext(Position x, List L);
2727
void Sort(List L);
28-
void Intersect(List L1, List L2, List Result);
28+
List Intersect(List L1, List L2);
2929
List Union(List L1, List L2);
30+
List Polynominal(int n);
31+
List PolynominalExp(List L, int n, int p);
3032

3133
#endif

Data Structures and Algorithm Analysis in C/List_Sample/List_Sample/List_Sample.vcxproj

+2
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,11 @@
7676
<ItemGroup>
7777
<ClCompile Include="List_Sample.c" />
7878
<ClCompile Include="Main.c" />
79+
<ClCompile Include="stack.c" />
7980
</ItemGroup>
8081
<ItemGroup>
8182
<ClInclude Include="List_Sample.h" />
83+
<ClInclude Include="Stack.h" />
8284
</ItemGroup>
8385
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
8486
<ImportGroup Label="ExtensionTargets">

Data Structures and Algorithm Analysis in C/List_Sample/List_Sample/List_Sample.vcxproj.filters

+6
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,16 @@
2121
<ClCompile Include="Main.c">
2222
<Filter>源文件</Filter>
2323
</ClCompile>
24+
<ClCompile Include="stack.c">
25+
<Filter>源文件</Filter>
26+
</ClCompile>
2427
</ItemGroup>
2528
<ItemGroup>
2629
<ClInclude Include="List_Sample.h">
2730
<Filter>头文件</Filter>
2831
</ClInclude>
32+
<ClInclude Include="Stack.h">
33+
<Filter>头文件</Filter>
34+
</ClInclude>
2935
</ItemGroup>
3036
</Project>

Data Structures and Algorithm Analysis in C/List_Sample/List_Sample/Main.c

+6-7
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
void main()
55
{
66
List L;
7-
List P, I;
7+
88

99
// ElementType x;
10-
L = CreateList();
11-
P = CreateList();
12-
I = InitEmpty();
10+
L = Polynominal(3);
11+
1312
// PrintList(L);
1413
/* PrintList(L);
1514
printf("enter the element you want to exchange\n");
@@ -18,8 +17,8 @@ void main()
1817
ExchangePosition_WithNext(P, L);
1918
*/
2019
// Sort(L);
21-
// Intersect(L, P, I);
22-
I = Union(L, P);
23-
PrintList(I);
20+
21+
// I = Union(L, P);
22+
PrintList(L);
2423
}
2524

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#ifndef _STACK_H_
2+
#define _STACK_H_
3+
4+
struct StackNode;
5+
typedef struct StackNode *PtrToNode;
6+
typedef PtrToNode Stack;
7+
8+
int IsEmpty(Stack S);
9+
Stack CreateStack(void);
10+
void MakeEmpty(Stack S);
11+
void Pop(Stack S);
12+
void Push(char x, Stack S);
13+
char Top(Stack S);
14+
#endif
15+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#include "stdlib.h"
2+
#include "stdio.h"
3+
#include "Stack.h"
4+
5+
struct StackNode
6+
{
7+
char Element;
8+
PtrToNode Next;
9+
};
10+
11+
int StackIsEmpty(Stack S)
12+
{
13+
return S->Next == NULL;
14+
}
15+
Stack CreateStack(void)
16+
{
17+
Stack S;
18+
S = malloc(sizeof(struct StackNode));
19+
if(S == NULL)
20+
{
21+
printf_s("Out of space");
22+
}
23+
S->Next = NULL;
24+
return S;
25+
}
26+
void MakeEmptyStack(Stack S)
27+
{
28+
if(S == NULL)
29+
{
30+
printf_s("must use Createstack first");
31+
}
32+
else
33+
{
34+
while(!IsEmpty(S))
35+
{
36+
Pop(S);
37+
}
38+
}
39+
}
40+
void Pop(Stack S)
41+
{
42+
PtrToNode FirstCell;
43+
if(IsEmpty(S))
44+
{
45+
printf_s("Empty stack");
46+
}
47+
else
48+
{
49+
FirstCell = S->Next;
50+
S->Next = S->Next->Next;
51+
free(FirstCell);
52+
}
53+
}
54+
void Push(char x, Stack S)
55+
{
56+
PtrToNode TmpCell;
57+
TmpCell = malloc(sizeof(struct StackNode));
58+
if(TmpCell == NULL)
59+
{
60+
printf_s("out of space");
61+
}
62+
else
63+
{
64+
TmpCell->Element = x;
65+
TmpCell->Next = S->Next;
66+
S->Next = TmpCell;
67+
}
68+
}
69+
70+
char Top(Stack S)
71+
{
72+
if(S->Next == NULL)
73+
{
74+
printf_s("stack is empty");
75+
return 0;
76+
}
77+
else
78+
{
79+
return S->Next->Element;
80+
}
81+
}

simple.c~

Whitespace-only changes.

0 commit comments

Comments
 (0)
0