谁能深入详细的讲下 返回指针的函数
谁能深入详细的讲下 返回指针的函数或这方面的书
程序代码:#include<stdio.h>
#include<malloc.h>
typedef struct Node{
int key;
struct Node *next;
}Node;
Node * Combine(Node * head1,Node * head2)
{
Node *p=(Node *)malloc(sizeof(Node));
Node *q=(Node *)malloc(sizeof(Node));
p=head1;
if( p ==NULL)
return head2;
while( NULL != p)
{
q=p;
p=p->next;
}
q->next=head2->next;
return head1;
}
void show( Node *head)
{
Node *q=head->next;
while(q!=NULL)
{
printf("%d ",q->key);
q=q->next;
}
}
int main()
{
Node * head1=(Node *)malloc(sizeof(Node));
Node * head2=(Node *)malloc(sizeof(Node));
Node *p=head1;
int i;
for(i=1;i<5;i++)
{
Node *q=(Node *) malloc(sizeof( Node));
q->key=i;
q->next=NULL;
p->next=q;
p=p->next;
}
show(head1);
printf("\n");
p=head2;
for(i=3;i<=4;i++)
{
Node *q=(Node *) malloc(sizeof(Node));
q->key=i;
q->next=NULL;
p->next=q;
p=p->next;
}
show(head2);
printf("\n");
Node *head=Combine(head1,head2);
show(head);
printf("\n");
return 0;
}