| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 459 人关注过本帖
标题:我真的找不出来 那里有问题了啊 !快疯了啊
只看楼主 加入收藏
某某
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2007-5-19
收藏
 问题点数:0 回复次数:5 
我真的找不出来 那里有问题了啊 !快疯了啊

#include<stdio.h>
#include<malloc.h>
#define NULL 0
struct node
{ int data ;
struct node *next;
};
struct node *createlink(int n)
{ struct node *head,*p,*q;
int i,a;
head=(struct node *)malloc(sizeof(struct node *));
p=q=head;
for(i=0;i<n;i++)
{ p=(struct node *)malloc(sizeof(struct node *));
scanf("%d",&a);
p->data=a;
q->next=p;
q=p;
}
p->next=NULL;
return head;
}
int length(struct node *head )
{ struct node *p;
int count=0;
p=head->next;
while(p!=NULL)
{ count++;
p=p->next;
}
return count;
}
struct node *insert(int length,struct node *head)
{struct node *r,*p,*q;
int j,x,a,b;
p=head;
while(p->next!=NULL)
{for(j=0;j<length-1;j++)
{p=p->next;
q=p->next;
if((p->data-q->data)>1)
{x=p->data-q->data;
for(j=0;j<x-1;j++)
{r=(struct node *)malloc(sizeof(struct node));
a=p->data;
r->data=a-1;
r->next=p->next;
p->next=r;
p=r;
}
}


if((q->data-p->data)>1)
{x=q->data-p->data;

for(j=0;j<x-1;j++)
{r=(struct node *)malloc(sizeof(struct node));
p->data=b;
r->data=b-1;
r->next=p->next;
p->next=r;
p=r;
}
}
}
}
return head;
}
print(struct node *head)
{ struct node *p;
p=head->next;
while(p!=NULL)
{printf("->%d",p->data);
p=p->next;
}
}
main()
{ struct node *head,*p;
int n,a;
scanf("%d",&n);
head=createlink(n);
print(head);
a=length(head);
p=insert(a,head);
print(p);
}
把链表中的数据按等差为1填充 如1->3->8->5 变为1->2->3->4->5->6->7->8->7->6->5

搜索更多相关主题的帖子: include return 
2007-06-01 21:22
huangfengchu
Rank: 1
等 级:新手上路
威 望:2
帖 子:274
专家分:0
注 册:2007-5-22
收藏
得分:0 

这么长的东西也不加注释?F了你!


深山苦学C语言,终年不见外面世界。
2007-06-01 21:23
ibiancheng
Rank: 1
等 级:新手上路
帖 子:148
专家分:0
注 册:2007-4-3
收藏
得分:0 
这么长,看着就晕,加点注释啥...

执著的信念,坚定的自信,勤奋的努力才是通向成功的捷径! !!
2007-06-01 21:40
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 
head=(struct node *)malloc(sizeof(struct node *));//下同,还没仔细检查.
p=q=head;
for(i=0;i<n;i++)
{ p=(struct node *)malloc(sizeof(struct node *));
scanf("%d",&a);

倚天照海花无数,流水高山心自知。
2007-06-01 22:02
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 
把变量声明中的struct删掉.还有建链表的也有问题.看看我写的
/******************************/
/* 尾插法建立带头结点的单链表 */
/******************************/
node* Creat_Node(int n)
{
node *head,*pre,*p;
int x;
head=(node*)malloc(sizeof(node));
head->next=NULL;
pre=head;
printf("输入%d个结点的值:",n);
for(int i=0;i<n;i++)
{
scanf("%d",&x);
p=(node*)malloc(sizeof(node));
p->data=x;
p->next=pre->next;
pre->next=p;
pre=pre->next;
}
return head;
}

倚天照海花无数,流水高山心自知。
2007-06-01 22:23
某某
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2007-5-19
收藏
得分:0 

#include<stdio.h>
#include<malloc.h>
#define NULL 0
struct node /*定义结构体*/
{ int data ;
struct node *next;
};
struct node *createlink(int n)/*创建带头接点的链表*/
{ struct node *head,*p,*q;
int i,a;
head=(struct node *)malloc(sizeof(struct node *));
p=q=head;
for(i=0;i<n;i++)
{ p=(struct node *)malloc(sizeof(struct node *));
scanf("%d",&a);
p->data=a;
q->next=p;
q=p;
}
p->next=NULL;
return head;
}
int length(struct node *head )/*计算链表的长度*/
{ struct node *p;
int count=0;
p=head->next;
while(p!=NULL)
{ count++;
p=p->next;
}
return count;
}
struct node *insert(int length,struct node *head)
{struct node *r,*p,*q;
int j,x,a,b;
p=head;
while(p->next!=NULL)
{for(j=0;j<length-1;j++)/*从头接点开始扫描*/
{p=p->next;
q=p->next;
if((p->data-q->data)>1)/*如果P的数据域大于q的数据域*/
{x=p->data-q->data;/*计算差值*/
for(j=0;j<x-1;j++)
{r=(struct node *)malloc(sizeof(struct node));/插入接点要求在p,q只间以p为为首项以1为公差递减到q*/
a=p->data;
r->data=a-1;
r->next=p->next;
p->next=r;
p=r;
}
}


if((q->data-p->data)>1) /*如果P的数据域大于q的数据域*/

{x=q->data-p->data;


for(j=0;j<x-1;j++)
{r=(struct node *)malloc(sizeof(struct node));/插入接点要求在p,q只间以p为为首项以1为公差递增到q*/
p->data=b;
r->data=b+1;
r->next=p->next;
p->next=r;
p=r;
}
}
}
}
return head;
}
print(struct node *head)/*输出链表*/
{ struct node *p;
p=head->next;
while(p!=NULL)
{printf("->%d",p->data);
p=p->next;
}
}
main()
{ struct node *head,*p;
int n,a;
scanf("%d",&n);
head=createlink(n);
print(head);
a=length(head);
p=insert(a,head);
print(p);
}

2007-06-01 23:33
快速回复:我真的找不出来 那里有问题了啊 !快疯了啊
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012429 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved