不能成功调用函数
#include <stdio.h>#include <stdlib.h>
#define LEN sizeof(LNode)
#define OVERFLOW 0
#define OK 1
typedef struct LNode {
int data;
struct LNode *next;
}LNode, *LinkList;
LinkList creat(LinkList p)
{
LinkList l, q;
int ch;
l = (LNode *) malloc( sizeof(LNode) );
if ( l )
{
l->data = 0;
l->next = NULL;
}
else
{
printf( "error\n" );
return NULL;
}
q = l;
p = l;
printf("Input the Incremental s:\n");
scanf("%d",&ch); //printf("%d\n",ch);
while (ch != 0)
{
p = (LNode*)malloc(LEN);
p->data = ch;
p->next = NULL;
q->next = p;
q = p;
scanf("%d",&ch);
//printf("%d\n",ch);
}
/* q = l;
while (q->next != NULL)
{
printf(" %d",q->next->data);
q = q->next;
}*/
return q;//It is OK!
}
LinkList Merge_List(LinkList A, LinkList B, LinkList C)
{
LinkList l;
/* l = (LNode*)malloc(LEN);
l->data = '\0';
l->next = NULL;
*/
l = (LNode *) malloc( sizeof(LNode) );
if ( l )
{
l->data = 0;
l->next = NULL;
}
else
{
printf( "error\n" );
return NULL;
}
// A = l;
// B = l;
while (A->next != NULL)
{
printf(" %d",A->next->data);
A = A->next;
}
while (B->next != NULL)
{
printf(" %d",B->next->data);
B = B->next;
}
/* C = A;
while (A->next != NULL && B->next != NULL)
{
if (A->data <= B->data)
{
C->next = A;
C = A;
A = A->next;
}
else
{
C->next = B;
C = B;
B = B->next;
}
}
C->next = A ? A : B;
C = l;
while (C->next != NULL)
{
printf(" %d",C->next->data);
C = C->next;
}
*/
free(A);
free(B);
return C;
}
/*
void Print(LinkList p)
{
LinkList q;
q = p;
if (p != NULL)
do {
printf(" %d",p->data);
p = p->next;
}
while (p != NULL);
free(p);
}*/
int main()
{
LinkList A, B, C;
A = (LNode *) malloc( sizeof(LNode) );
if ( A )
{
A->data = 0;
A->next = NULL;
}
else
{
printf( "error\n" );
return -1;
}
B = A;
A = creat(A);
B = creat(B);
/* C = (LNode *) malloc( sizeof(LNode) );
if ( C )
{
C->data = 0;
C->next = NULL;
}
else
{
printf( "error\n" );
return -1;
}
*/
C = A;
C = Merge_List(A, B, C);
/* while (C->next != NULL)
{
printf(" %d",C->next->data);
C = C->next;
}*/
// Print(C);
return 0;
}
此道是莱鸟我编得;但不能成功运行~我尝试许多方法,其中一种就是上面用的方法;发现程序好像总是不通过LinkList Merge_List函数~为什么??望各位高手指点~