标签:
#include <stdio.h> struct node{ char data; struct node *next; } NODE; struct node *find(struct node *str1, struct node *str2){ int str1_len = 0, str2_len = 0; struct node *p = str1; while(p->next != NULL){ str1_len++; p = p->next; } p = str2; while(p->next != NULL){ str2_len++; p = p->next; } int i, tmp; if(str1_len > str2_len){ tmp = str1_len - str2_len; for(i=0; i<tmp; i++){ str1 = str1->next; } }else{ tmp = str2_len - str1_len; for(i=0; i<tmp; i++){ str2 = str2->next; } } p = NULL; while(str1 != NULL){ if(str1->data == str2->data){ if(p == NULL){ p = str1; } }else{ p = NULL; } str1 = str1->next; str2 = str2->next; } return p; }
标签:
原文地址:http://www.cnblogs.com/bai-jimmy/p/5343481.html