首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

这个链表的代码到底错哪了啊请指点

2012-03-25 
这个链表的代码到底哪里错了啊?请各位高手指点#includestdafx.h #includeiostream.h#includestdlib.h

这个链表的代码到底哪里错了啊?请各位高手指点
#include   "stdafx.h "
#include   <iostream.h>
#include   <stdlib.h>

typedef   struct   ElementT{
char   data;
struct   ElementT   *next;
}LNode,*LinkList;

LinkList   p,q;

void   CreateNode(LinkList   &l,int   n)
{
l=(LinkList)malloc(sizeof(LNode));
l-> next=NULL;
for   (int   i=n;   i> 0;   --i)
{
p=(LinkList)malloc(sizeof(LNode));
scanf(&p-> data);
p-> next=l-> next;
l-> next=p;
}

}

void   print(LinkList   &l)
{
LinkList   p;
p=l;
while(p-> next!=NULL)
{
cout < <p-> data < <endl;
p=p-> next;
}
}

int   main(int   argc,   char*   argv[])
{
printf( "Hello   World!\n ");
LinkList   head;
CreateNode(head,4);
print(head);
return   0;
}

[解决办法]
void CreateNode(LinkList &l,int n)
{
l=(LinkList)malloc(sizeof(LNode));
l-> next=NULL;
for (int i=n; i> 0; --i)
{
p=(LinkList)malloc(sizeof(LNode));
scanf( "%d ",&p-> data); //这里
p-> next=l-> next;
l-> next=p;
}

}

热点排行