注册 登录
编程论坛 C++教室

链表死循环了 帮忙救下

lwp001 发布于 2009-10-11 19:39, 590 次点击
#include<iostream.h>
#include"malloc.h"
struct node
{
   int data;

  struct node *next;
};
 struct node *next,*null,*p,*L,*s,*q;
 int j,e,n,k;
 void create( )
{

   
   L=(struct node *)malloc(sizeof(struct node));
   L->next=null;
   s=L;
   
    while(k!=-1)
   {
     cin>>k;
     p=(struct node *)malloc(sizeof(struct node));
     p->data=k;
     s->next=p;
     s=p;
   }
  p->next=null;
}

void showL()
{
cout<<"您所建立的链表如下:"<<endl;

while(p!=null)
   {
    p=L->next;
    cout<<p->data<<" ";
    p=p->next;
}
}
int main()
{
   create();

showL();

return 0;
}
 谢谢!!!帮下忙啊~~~
2 回复
#2
pywepe2009-10-11 20:15
回复 楼主 lwp001
程序代码:
while(p!=null)
   {
    p=L->next;
    cout<<p->data<<" ";
    p=p->next;
}

p指一个结点
p跳到下一个结点
p又回到L->next
...

还有一个问
这个链表在哪?
只有结点

你得有一个
struct list{
   Node* head;
}



[ 本帖最后由 pywepe 于 2009-10-11 20:17 编辑 ]
#3
lwp0012009-10-11 20:25
谢谢 ! 你最后说的我在书上还没见过
1