user-0 提问: 链表合并函数有点不明白，新手求助！

回复:
user: user-1
content: 如果不通过返回值从而修改headc的指向，那么必须传入二级指针或者一级指针的引用 这里以二级指针为例：  #include<stdio.h> #include<stdlib.h> #define ERROR 0; #define OK 1; typedef struct Lnode{ 	int data; 	struct Lnode *next; }Lnode; Lnode *initial(void); //Lnode *merge(Lnode *heada,Lnode *headb); void merge(Lnode *heada,Lnode *headb,Lnode **headc); int getelem(Lnode *L_first ,int loca,int *elem_need);   int main() { 	int elem1,elem2,elem3; 	Lnode *heada,*headb,*headc; 	heada = initial(); 	headb = initial(); 	getelem(heada,4,&elem1); 	getelem(headb,4,&elem2); 	printf("elem1= %d,elem2 = %d\n",elem1,elem2); 	//headc = merge(heada,headb); 	merge(heada,headb,&headc); 	printf("???\n"); 	getelem(headc,5,&elem3); 	printf("???\n"); 	printf("headc5 = %d\n",elem3); 	return 0; }  void merge(Lnode *heada,Lnode *headb,Lnode **headc) {     Lnode *ptra;     Lnode *ptrb;     Lnode *ptrc;     ptra = heada->next;     ptrb = headb->next;     *headc = ptrc = heada;     while(ptra && ptrb){         if(ptra->data<ptrb->data){                 printf("????\n");             ptrc->next = ptra;             ptrc = ptra;             ptra = ptra->next;         }         else{             ptrc->next = ptrb;             ptrc = ptrb;             ptrb = ptrb->next;         }     }     ptrc->next=ptra?ptra:ptrb;     free(ptrb); 	//*headc=ptrc; }  /* Lnode *merge(Lnode *heada,Lnode *headb) { 	Lnode *ptra,*ptrb,*ptrc; 	Lnode *headc; 	ptra = heada->next; 	ptrb = headb->next; 	headc = ptrc = heada; 	while(ptra && ptrb){ 		if(ptra->data<ptrb->data){ 			ptrc->next = ptra; 			ptrc = ptra; 			ptra = ptra->next; 		} 		else{ 			ptrc->next = ptrb; 			ptrc = ptrb; 			ptrb = ptrb->next; 		} 	} 	ptrc->next=ptra?ptra:ptrb; 	free(ptrb); 	return headc; } */ int getelem(Lnode *L_first ,int loca,int *elem_need) { 	//L为指向struct Lnode的指针。 	//寻在第loca个元素，将其值赋值给elem_need指向的值返回ok否则ERROR. 	int cnt=1; 	Lnode *Pointer; 	Pointer = L_first->next; 	while(Pointer && cnt<loca){ 		cnt++; 		Pointer = Pointer -> next; 	} 	if(!Pointer || cnt>loca){ 		return ERROR; 	} 	*elem_need = Pointer->data; 	return OK; } Lnode *initial(void) { 	Lnode *head; 	Lnode *ptr1,*ptr2; 	int judge=0; 	head = (Lnode *)malloc(sizeof(Lnode)); 	ptr1=ptr2=(Lnode *)malloc(sizeof(Lnode)); 	printf("enter the data:\n"); 	scanf("%d",&ptr1->data); 	while(ptr1->data>0){ 		judge += 1; 		if(judge==1){ 			head->next = ptr1; 			ptr2 = ptr1; 		} 		else{ 			ptr2->next = ptr1; 			ptr2 = ptr1; 		} 		ptr1 = (Lnode *)malloc(sizeof(Lnode)); 		printf("enter the data:\n"); 		scanf("%d",&ptr1->data); 	} 	ptr2->next = NULL; 	free(ptr1); 	ptr1 = NULL; 	return head; }

user: user-0
content: 在主函数用getelem获取结点数值的时候 无法获得合并链表后的值 但是在函数merge中调用就可以。

user: user-0
content: 把函数merge改为这样的形式 不用return   void merge(Lnode *heada,Lnode *headb,Lnode *headc) {     Lnode *ptra;     Lnode *ptrb;     Lnode *ptrc;     ptra = heada->next;     ptrb = headb->next;     headc = ptrc = heada;     while(ptra && ptrb){         if(ptra->data<ptrb->data){                 printf("????\n");             ptrc->next = ptra;             ptrc = ptra;             ptra = ptra->next;         }         else{             ptrc->next = ptrb;             ptrc = ptrb;             ptrb = ptrb->next;         }     }     ptrc->next=ptra?ptra:ptrb;     free(ptrb); } 然后调试的时候就有问题？？？为什么呢   求助大神帮助