莱鸟请教链表的问题
#include <stdio.h>#include <stdlib.h>
#define LIST_INIT_SIZE 100
#define LEN sizeof(LinkList)
#define NULL 0
typedef struct LNode {
int data;
struct LNode *next;
}LNode, *LinkList;
LinkList creat(LinkList &head)
{
LinkList l, q, p;
int ch;
l = (LNode*)malloc(sizeof(LNode));
l->data = '\0';
l->next = NULL;
q = l;
printf("Input the s:\n");
scanf("%d",&ch); //printf("%d\n",ch);
getchar();
while (ch != 0)
{
p = (LNode*)malloc(sizeof(LNode));
p->data = ch;
p->next = NULL;
q->next = p;
q = p;
scanf("%d",&ch);
//printf("%d\n",ch);
getchar();
}
/* q = l;
while (q->next != NULL)
{
printf("%d",q->next->data);
q = q->next;
}*/
return q;//It is OK!
}
int main()
{
LinkList a, b;//, c;
LinkList l;//, p;
l = (LNode*)malloc(LEN);
l->data = '\0';
l->next = NULL;
a = l;
b = l;
// c = l;
creat(a);
a = l;
while (a->next != NULL)
{
printf("%d",a->next->data);
a = a->next;
}
creat(b);
b = l;
while (b->next != NULL)
{
printf("%d",b->next->data);
b = b->next;
}
//Print(a);
//Print(b);
/* Merge(a, b, c);
p = l;
p = opposite(c);
printf("Output the Descending series:\n");
Print(p);
*/
return 0;
}
上程序是其中以部分,我是刚刚学数据结构的,想向各位高手请教请教~
为什么我这个主程序体不能如自己所愿打印出a与b的值呢??
在LinkList creat可以打印出其值,但调用时就打印不出来??
为什么会这样??莱鸟我想了近一个星期咯~~没办法~~希望各位帮帮忙~
~谢谢先~