合并2.0
This commit is contained in:
parent
285c764123
commit
dcbc9f6ab2
@ -18,15 +18,15 @@
|
||||
<ClCompile Include="main.c">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="sq_list.c">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="linked_list.c">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="linked_list_stack.c">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="sq_list.c">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="sq_list.h">
|
||||
|
@ -2,7 +2,7 @@
|
||||
<Project>
|
||||
<ProjectOutputs>
|
||||
<ProjectOutput>
|
||||
<FullPath>C:\code\lencode\Project2\Debug\Project2.exe</FullPath>
|
||||
<FullPath>C:\Users\段宇宸\Documents\GitHub\Project2\Debug\Project2.exe</FullPath>
|
||||
</ProjectOutput>
|
||||
</ProjectOutputs>
|
||||
<ContentFiles />
|
||||
|
@ -1,2 +1 @@
|
||||
sq_list.c
|
||||
Project2.vcxproj -> C:\code\lencode\Project2\Debug\Project2.exe
|
||||
Project2.vcxproj -> C:\Users\段宇宸\Documents\GitHub\Project2\Debug\Project2.exe
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,4 +1,4 @@
|
||||
C:\code\lencode\Project2\linked_list.c;C:\code\lencode\Project2\Project2\Debug\linked_list.obj
|
||||
C:\code\lencode\Project2\linked_list_stack.c;C:\code\lencode\Project2\Project2\Debug\linked_list_stack.obj
|
||||
C:\code\lencode\Project2\main.c;C:\code\lencode\Project2\Project2\Debug\main.obj
|
||||
C:\code\lencode\Project2\sq_list.c;C:\code\lencode\Project2\Project2\Debug\sq_list.obj
|
||||
C:\Users\段宇宸\Documents\GitHub\Project2\linked_list.c;C:\Users\段宇宸\Documents\GitHub\Project2\Project2\Debug\linked_list.obj
|
||||
C:\Users\段宇宸\Documents\GitHub\Project2\linked_list_stack.c;C:\Users\段宇宸\Documents\GitHub\Project2\Project2\Debug\linked_list_stack.obj
|
||||
C:\Users\段宇宸\Documents\GitHub\Project2\main.c;C:\Users\段宇宸\Documents\GitHub\Project2\Project2\Debug\main.obj
|
||||
C:\Users\段宇宸\Documents\GitHub\Project2\sq_list.c;C:\Users\段宇宸\Documents\GitHub\Project2\Project2\Debug\sq_list.obj
|
||||
|
@ -1,2 +1,2 @@
|
||||
PlatformToolSet=v143:VCToolArchitecture=Native32Bit:VCToolsVersion=14.43.34808:TargetPlatformVersion=10.0.26100.0:
|
||||
Debug|Win32|C:\code\lencode\Project2\|
|
||||
PlatformToolSet=v143:VCToolArchitecture=Native32Bit:VCToolsVersion=14.43.34808:TargetPlatformVersion=10.0.22621.0:
|
||||
Debug|Win32|C:\Users\段宇宸\Documents\GitHub\Project2\|
|
||||
|
Binary file not shown.
Binary file not shown.
@ -1,2 +1,2 @@
|
||||
^C:\CODE\LENCODE\PROJECT2\PROJECT2\DEBUG\LINKED_LIST.OBJ|C:\CODE\LENCODE\PROJECT2\PROJECT2\DEBUG\LINKED_LIST_STACK.OBJ|C:\CODE\LENCODE\PROJECT2\PROJECT2\DEBUG\MAIN.OBJ|C:\CODE\LENCODE\PROJECT2\PROJECT2\DEBUG\SQ_LIST.OBJ
|
||||
C:\code\lencode\Project2\Project2\Debug\Project2.ilk
|
||||
^C:\USERS\段宇宸\DOCUMENTS\GITHUB\PROJECT2\PROJECT2\DEBUG\LINKED_LIST.OBJ|C:\USERS\段宇宸\DOCUMENTS\GITHUB\PROJECT2\PROJECT2\DEBUG\LINKED_LIST_STACK.OBJ|C:\USERS\段宇宸\DOCUMENTS\GITHUB\PROJECT2\PROJECT2\DEBUG\MAIN.OBJ|C:\USERS\段宇宸\DOCUMENTS\GITHUB\PROJECT2\PROJECT2\DEBUG\SQ_LIST.OBJ
|
||||
C:\Users\段宇宸\Documents\GitHub\Project2\Project2\Debug\Project2.ilk
|
||||
|
Binary file not shown.
BIN
Project2/Debug/main.obj.enc
Normal file
BIN
Project2/Debug/main.obj.enc
Normal file
Binary file not shown.
BIN
Project2/Debug/sq_list.obj.enc
Normal file
BIN
Project2/Debug/sq_list.obj.enc
Normal file
Binary file not shown.
10
main.c
10
main.c
@ -10,10 +10,10 @@ int main(void)
|
||||
|
||||
sq_list* L = init_sq_list();
|
||||
sq_list* N = init_sq_list();
|
||||
for (int i = 1; i <= 3; i++)
|
||||
{
|
||||
N->data[i - 1] = i;
|
||||
}
|
||||
N->data[0] = 11;
|
||||
N->data[1] = 12;
|
||||
N->data[2] = 13;
|
||||
|
||||
for (int i = 1; i <= 10; i++)
|
||||
{
|
||||
L->data[i - 1] = i;
|
||||
@ -23,7 +23,7 @@ int main(void)
|
||||
print_sq_list(N);
|
||||
print_sq_list(L);
|
||||
printf("----------------------------------");
|
||||
merge_sq_list(N,L);
|
||||
mer_ge_sq_list(L,N);
|
||||
print_sq_list(L);
|
||||
printf("%d", L->length);
|
||||
printf("Hello World!\n");
|
||||
|
61
sq_list.c
61
sq_list.c
@ -27,6 +27,7 @@ void delete_sq_list(sq_list* list,int pos)
|
||||
list->data[list->length - 1] = 0;
|
||||
}
|
||||
list->length--;
|
||||
|
||||
}
|
||||
|
||||
// Ìæ»»
|
||||
@ -77,6 +78,43 @@ void print_sq_list(sq_list* list)
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
//获得元素
|
||||
void get_sq_list(sq_list* list1, int pos, int*e)
|
||||
{
|
||||
if (list1->length == 0 || pos<0 || pos>list1->length)
|
||||
{
|
||||
printf("获取元素失败");
|
||||
return;
|
||||
}
|
||||
*e = list1->data[pos];
|
||||
return;
|
||||
}
|
||||
|
||||
//查找
|
||||
int locate_list(sq_list* list, int *e)
|
||||
{
|
||||
int i = 0;
|
||||
if (list->length == 0)
|
||||
{
|
||||
printf("表长为空");
|
||||
return;
|
||||
}
|
||||
for (i = 0;i < list->length;i++)
|
||||
{
|
||||
if (list->data[i] == e)
|
||||
return 1;
|
||||
}
|
||||
if (i > list->length)
|
||||
{
|
||||
printf("越界错误");
|
||||
return;
|
||||
}
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 2 µ½ 1
|
||||
void merge_sq_list(sq_list* list_1, sq_list* list_2)
|
||||
{
|
||||
@ -113,4 +151,25 @@ void merge_sq_list(sq_list* list_1, sq_list* list_2)
|
||||
//if (list_1->data[j] != list_2->data[i])
|
||||
//continue;
|
||||
//else if (list_1->data[j] == list_2->data[i])
|
||||
//break;
|
||||
//break;
|
||||
|
||||
//合并2.0
|
||||
void mer_ge_sq_list(sq_list* list_1, sq_list* list_2)
|
||||
{
|
||||
int e;
|
||||
int k = 0;
|
||||
for (int k=0;k < list_2->length;k++);
|
||||
{
|
||||
get_sq_list(list_2,k,&e);
|
||||
if(!locate_list(list_1,list_2))
|
||||
insert_sq_list(list_1,list_1->length, e);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
10
sq_list.h
10
sq_list.h
@ -24,8 +24,16 @@ void insert_sq_list(sq_list* list, int pos, int value);
|
||||
// ´òÓ¡
|
||||
void print_sq_list(sq_list* list);
|
||||
|
||||
// 合并顺序表
|
||||
//»ñµÃÔªËØ
|
||||
void get_sq_list(sq_list* list1,int pos, int *e);
|
||||
|
||||
//²éÕÒ
|
||||
int locate_list(sq_list* list, int e);
|
||||
|
||||
// ºÏ²¢Ë³Ðò±í1.0
|
||||
void merge_sq_list(sq_list* list_1, sq_list* list_2);
|
||||
|
||||
//ºÏ²¢Ë³Ðò±í2.0
|
||||
void mer_ge_sq_list(sq_list* list_1, sq_list* list_2);
|
||||
#endif
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user