谁来帮我运行下,老出现内存不可读???

作者在 2010-03-22 22:23:03 发布以下内容
#include "iostream.h"
#include "malloc.h"
typedef struct LNode
{
 int data;
 struct LNode *next;
}LNode,*LinkList;
void CreateList(LinkList L)
{
 LinkList p,q;
 int i=1;
 L=(LNode*)malloc(sizeof(LNode));
 if(L==NULL)
  cout<<"error!";
 p=L;
 while(p!=NULL&&i!=0)
 {
  q=(LNode*)malloc(sizeof(LNode));
  if(q==NULL)
   cout<<"malloc error"<<endl;
  cout<<"input the data(end with 0):"<<endl;
  cin>>q->data;
  i=q->data;
  p->next=q;
  p=q;
 }
 
}
void PrintList(LinkList L)
{
 LinkList p;
 p=L->next;
 while(p!=NULL)
 {
  cout<<p->data<<endl;
  p=p->next;
 }
}
 void main()
 {
 LNode L;
 CreateList(&L);
 PrintList(&L);
 }
默认分类 | 阅读 751 次
文章评论,共2条
源本英明C
2010-06-10 16:46
1
<img src="image/face/3.gif" class="face">
奋斗的懒虫(作者)
2010-08-25 12:55
2
游客请输入验证码
文章分类