高手帮忙指点一下,一个链表问题

humincq 2007-04-22 10:57:17
#include<iostream>
#include<stdlib.h>
#include<conio.h>
using namespace std;
typedef struct LNode{
int data;
struct LNode *next;
}LNode,*Linklist;
int CreateList(Linklist &L,int n)
{ Linklist p;int i;
L=(Linklist)malloc(sizeof(LNode));
L->next==NULL;
for(i=1;i<=n;i++)
{p=(Linklist)malloc(sizeof(LNode));
cin>>p->data;L->next=p;p->next=L->next;}
int ListDelete(Linklist &L,int i,int &e)
{ Linklist q, p;p=L;int e,j=0;
while(p->next&&j<i-1)
{p=p->next;j++;}
if(!(p->next)||j>i-1) return 0;
else q=p->next;p->next=q->next;
e=q->data;free(q);
return 1;
}
void main()
{ int a,b,c,i,j;
Linklist L p,q;q=p=L;
cout<<"please enter the len of the list:";
cin>>a;
cout<<endl<<"please enter the datas:";
CreateList(L,a);
cout<<"the list is:"
for(i=0;i<a;i++)
{cout<<p->data;p=p->next;}
cout<<"enter the weizhi dele:";
cin>>b;
ListDelete(L,b,c);
for(j=0;j<a-1;j++)
{cout<<q->data;q=q->next);}
cout<<endl<<c;}
为和编译通不过呢,谢谢!
...全文
171 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
tsrs 2007-04-22
  • 打赏
  • 举报
回复
代码格式太乱,整理一下你会发现问题的。
lin_style 2007-04-22
  • 打赏
  • 举报
回复
int CreateList(Linklist &L,int n)
{
Linklist p;int i;
L=(Linklist)malloc(sizeof(LNode));
L->next==NULL;
for(i=1;i<=n;i++)
{
p=(Linklist)malloc(sizeof(LNode));
cin>>p->data;L->next=p;p->next=L->next;
}

//{}配对
mochen5460 2007-04-22
  • 打赏
  • 举报
回复
错误在哪里?
ylfeng86 2007-04-22
  • 打赏
  • 举报
回复
如果不输入字符窜长度,又该怎样解决呢?

65,213

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧