user-0 提问: 问一下哪错了

回复:
user: user-1
content: 仅供参考：#include <algorithm> #include <iostream> #include <functional> #include <cstring> using namespace std; int main() {     char *Alphabet = "abcdefghijklmnopqrstuvwxyz" ;     char *Vowels   = "aeiou" ;     char *AlphaNum = "0123456789abcdef" ;     char result[45] ;     char *last ;      int lenA  = strlen(Alphabet) ;     int lenV  = strlen(Vowels  ) ;     int lenAN = strlen(AlphaNum) ;      cout << "Alphabet = " << Alphabet << endl ;     cout << "Vowels   = " << Vowels   << endl ;     cout << "AlphaNum = " << AlphaNum << endl ;      cout << "\nusing non-predicate versions" << endl ;      //non-predicate set_difference     last = set_difference(Alphabet, Alphabet+lenA,                           AlphaNum, AlphaNum+lenAN,                           result) ;     *last = 0 ;     cout << "set_difference(Alphabet, AlphaNum) =  " << result << endl ;      //non-predicate set_intersection     last = set_intersection(Alphabet, Alphabet+lenA,                             AlphaNum, AlphaNum+lenAN,                             result) ;     *last = 0 ;     cout << "set_intersection(Alphabet, AlphaNum) =  " << result << endl ;      //non-predicate set_symmetric_difference     last = set_symmetric_difference(Alphabet, Alphabet+lenA,                                     Vowels  , Vowels  +lenV,                                     result) ;     *last = 0 ;     cout << "set_symmetric_difference(Alphabet, Vowels) =  " << result << endl ;      //non-predicate set_union     last = set_union(Alphabet, Alphabet+lenA,                      AlphaNum, AlphaNum+lenAN,                      result) ;     *last = 0 ;     cout << "set_union(Alphabet, AlphaNum) =  " << result << endl ;      cout << "\nusing predicate versions" << endl ;      //predicate set_difference     last = set_difference(Alphabet, Alphabet+lenA,                           AlphaNum, AlphaNum+lenAN,                           result  , less<char>()) ;     *last = 0 ;     cout << "set_difference(Alphabet, AlphaNum) =  " << result << endl ;      //predicate set_intersection     last = set_intersection(Alphabet, Alphabet+lenA,                             AlphaNum, AlphaNum+lenAN,                             result  , less<char>()) ;     *last = 0 ;     cout << "set_intersection(Alphabet, AlphaNum) =  " << result << endl ;      //predicate set_symmetric_difference     last = set_symmetric_difference(Alphabet, Alphabet+lenA,                                     Vowels  , Vowels  +lenV,                                     result  , less<char>()) ;     *last = 0 ;     cout << "set_symmetric_difference(Alphabet, Vowels) =  " << result << endl ;      //predicate set_union     last = set_union(Alphabet, Alphabet+lenA,                      AlphaNum, AlphaNum+lenAN,                      result  , less<char>()) ;     *last = 0 ;     cout << "set_union(Alphabet, AlphaNum) =  " << result << endl ;      return 0 ; }

user: user-2
content: //循环变量建议使用i, j, k; 函数名建议使用非拼音（可以通过英汉翻译软件或在线的做一下翻译） //算法没问题，只是输出时有一点小问题；%s换成%c     4 void intersection(struct jihe *a,struct jihe *b)//两个集合求交集     5 {         6     struct jihe *c,*d,*e,*s;     7     char q[20];     8     int i, j;     9     e = a;    10     i = 0;    11     while(e)    12     {    13     |   d = b;    14     |   while(d)    15     |   { >> 16     |   |   if(e->c == d->c)    17     |   |   |   break;    18     |   |   else >> 19     |   |   |   d = d->next;    20     |   }    21     |   if(d != NULL)    22     |   { >> 23     |   |   q[i] = e->c;    24     |   |   i++;    25     |   } >> 26     |   e = e->next;    27     }    28          29     for(j = 0; j < i; j++)    30     {    31     |   printf("%c", q[j]);   //此处改成%c    32     }    33 }        34

user: user-3
content: 对你的代码做了修改,自己分析自己的代码,理解一下。 #include <stdio.h> #include <stdlib.h>  struct jihe { char c; struct jihe *next; }; struct jihe *qjiaoji(struct jihe *a,struct jihe *b)//两个集合求交集 { struct jihe *c,*d,*r; c = r = (struct jihe*)malloc(sizeof(struct jihe)); r->next = NULL; while(a) { d=b; while(d) { if(a->c==d->c) { r->c=a->c; r->next=(struct jihe*)malloc(sizeof(struct jihe)); r=r->next; r->next=NULL; } d=d->next; } a=a->next; }     return c; } struct jihe *write(int m)//这是个建立集合的过程 {     int q;     char o; struct jihe *sa,*sb,*sc; sa=NULL; for(q=0;q<m;q++) { sc=(struct jihe*)malloc(sizeof(struct jihe));         scanf("%c",&o);         sc->c=o;         if(sa==NULL)         {          sa=sc;          sb=sc;         }         else         {          sb->next=sc;          sb=sc;         } } sc->next=NULL; return sa; }  int main (void) { 	struct jihe * t = qjiaoji(write(5),write(5)); 	while(t->next) 	{ 		printf("%c\t",t->c); 		t=t->next; 	} 	return 0; } 测试:

user: user-0
content: 顶。。。。。。。。。。。。。。。。。

user: user-4
content: 崩溃的时候在弹出的对话框按相应按钮进入调试，按Alt+7键查看Call Stack即“调用堆栈”里面从上到下列出的对应从里层到外层的函数调用历史。双击某一行可将光标定位到此次调用的源代码或汇编指令处，看不懂时双击下一行，直到能看懂为止。  代码功能归根结底不是别人帮自己看或讲解或注释出来的；而是被自己静下心来花足够长的时间和精力亲自动手单步或设断点或对执行到某步获得的中间结果显示或写到日志文件中一步一步分析出来的。 提醒：再牛×的老师也无法代替学生自己领悟和上厕所！ 单步调试和设断点调试（VS IDE中编译连接通过以后，按F10或F11键单步执行，按Shift+F11退出当前函数；在某行按F9设断点后按F5执行停在该断点处。）是程序员必须掌握的技能之一。

user: user-5
content: 返回的交集 应该申请内存,  建立集合的函数名不能用wirte这与系统API重复命令 输入的时候scanf不能用%s只能用%c, %s会有字符串结尾字符溢出的问题   #include <stdio.h> #include <stdlib.h>  struct jihe { 	char c; 	struct jihe *next; };  struct jihe *qjiaoji(struct jihe *a, struct jihe *b)//两个集合求交集 { 	struct jihe *c = NULL, *d, *tmp = NULL, *tail = NULL; 	 	while(a) { 		d = b; 		while(d) { 			if(a->c == d->c) { 				tmp = (struct jihe *)malloc(sizeof(struct jihe)); 				tmp->c = a->c; 				tmp->next = NULL; 				if (!c) { 					c = tmp; 					tail = tmp; 				} 				tail->next = tmp; 				tail = tmp; 			} 			d = d->next; 		} 		a=a->next; 	} 	return c; }  struct jihe *jihe_write(int m)//这是个建立集合的过程 {     int i;     char o; 	struct jihe *head = NULL, *tail = NULL, *tmp; 	 	fflush(stdin);//only work in VC 	for(i = 0;i < m; i++) { 		tmp = (struct jihe*)malloc(sizeof(struct jihe)); 		scanf("%c", &(tmp->c)); 		tmp->next = NULL; 	    if (NULL == head) { 	        head = tmp; 	        tail = tmp; 	    } 	    else { 	        tail->next=tmp; 	        tail = tmp; 	        } 	} 	 	return head; }  void jihe_print(struct jihe* head) { 	while (head) { 		printf("%c ", head->c); 		head = head->next; 	} 	printf("\n"); }  void jihe_free(struct jihe* head) { 	struct jihe* tmp; 	 	while (head) { 		tmp = head; 		head = head->next; 		free(tmp); 	} }  int main(int argc, char** argv) { 	struct jihe * jihe1 = NULL; 	struct jihe * jihe2 = NULL; 	struct jihe * jiaoji = NULL;	 	 	jihe1 = jihe_write(5); 	printf("jihe1 is:\n\t"); jihe_print(jihe1); 	jihe2 = jihe_write(6); 	printf("jihe2 is:\n\t"); jihe_print(jihe2); 	 	jiaoji = qjiaoji(jihe1, jihe2);  	printf("jiao ji is:\n\t"); jihe_print(jiaoji); 	 	jihe_free(jihe1); 	jihe_free(jihe2); 	jihe_free(jiaoji); 	 	return 0;	 }

user: user-0
content: void jiaoji(struct jihe *a,struct jihe *b)//两个集合求交集 { 	struct jihe *c,*d,*e,*s; 	char q[20]; 	int y,u; 	e=a; 	y=0; 	while(e) 	{ 		d=b; 		while(d) 		{ 			if(e->c==d->c) 			    break; 			else 			d=d->next; 		} 		if(d!=NULL) 		{ 			q[y]=e->c; 			y++; 		} 		e=e->next; 	}     for(u=0;u<y;u++) 	{ 		printf("%s",q[u]);     } }   是这个，不好意思