更新合并函数

This commit is contained in:
Jdhggg 2025-03-21 00:59:03 +08:00
parent 7935f0fbe0
commit cd0fee3b69
5 changed files with 13 additions and 11 deletions

View File

@ -1,2 +1,4 @@
 main.c  main.c
sq_list.c
正在生成代码...
Project2.vcxproj -> C:\code\lencode\Project2\Debug\Project2.exe Project2.vcxproj -> C:\code\lencode\Project2\Debug\Project2.exe

View File

@ -62,7 +62,7 @@ void insert_sq_list(sq_list* list, int pos, int value)
list->data[i + 1] = list->data[i]; list->data[i + 1] = list->data[i];
} }
list->data[pos] = value; list->data[pos] = value;
if (flog + 1 > list->length) /* if (flog + 1 > list->length)*/
list->length++; list->length++;
} }
@ -96,21 +96,21 @@ void merge_sq_list(sq_list* list_1, sq_list* list_2)
for (int j = 0; j < list_1->length; j++) for (int j = 0; j < list_1->length; j++)
{ {
if (list_1->data[j] != list_2->data[i]) if (list_1->data[j] != list_2->data[i])
continue;
else if (list_1->data[j] == list_2->data[i])
{ {
flog++; break; if (j == list_1->length -1)
}
else
{ {
list_1->data[list_1->length] = list_2->data[i]; list_1->data[list_1->length] = list_2->data[i];
list_1->length++; list_1->length++;
flog++;
}
else
continue;
} }
} }
} }
printf("----------------------------------\n"); printf("----------------------------------\n");
printf("有%d相同 有%d相同\n", flog, list_2->length - flog); printf("有%d相同 有%d相同\n", flog, list_2->length - flog);
printf("----------------------------------\n"); printf("----------------------------------\n");
} }