下面是查找重复字符串模式的算法。所有的字符串都已经被添加到一个链表中,现在的工作是找到一个重复的模式。
字符串长度可以是8-20个字符,链表中字符串元素的数量在100到200之间。目前的方法似乎存在复杂性和效率问题。有人可以为此提出最有效的方法吗?
typedef struct Map
{
int8_t *string;
struct Map *next;
}map_t;
//Algorithm to find the duplicate string pattern in link list.
int16_t findDuplicateOids(map_t *head)
{
map_t *ptr1, *ptr2;
ptr1 = head;
/* Pick elements one by one */
while(ptr1 != NULL && ptr1->next != NULL)
{
ptr2 = ptr1;
/* Compare the picked element with rest of the elements */
while(ptr2->next != NULL)
{
/* If pattern is similar than return return error */
if(!strcmp(ptr1->string , ptr2->next->string))
{ printf("match …Run Code Online (Sandbox Code Playgroud)