| 网站首页 | 业界新闻 | 小组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
 🍻🍻🍻🍻🍻编程论坛祝大家春节愉快，阖家欢乐 🎆🎆🎆🎆🎆 2019所有的心愿，在2020都能实现❤️❤️❤️❤️❤️

已结贴   问题点数：10  回复次数：3
NSB600"CL.EXE"已退出，代码为2

```#include<stdio.h>
#include<stdlib.h>

struct node
{
int data;
struct node* next;
struct node* prior;
};
void initlist(node* p);
void conversion(node* q);
void Printf(node* q);
int main()
{
node* p;
p = (struct  node*)malloc(sizeof(node));
p->next = NULL;
p->prior = NULL;
p->data = -1;
initlist(p);
conversion(p);
//Printf(p);
}
void initlist(node* q)
{
int i;
struct node* k,*p;
p->data = 0;
k= q->next;
while (i<10)
{
struct node*s= (struct  node*)malloc(sizeof(node));
s->data = p->data ++;
s->prior = k;
k->next = s;
k = k->next;
s->next = NULL;
}
}
void conversion(node* q)
{
int i;
struct node* p,*s;
s = q->next;
while (s->data !=NULL)
{
if (s->next == NULL)
p = s;
s = s->next;
}
s = q->next;
while (&s !=& p || s->prior != p)
{
s->data = s->data + p->data;
p->data = s->data - p->data;
s->data = s->data - p->data;
p = p->prior;
s = s->next;
}
}

void Printf(node* q)
{
struct node* p;
p = q->next;
while (p->next == NULL)
{
printf("%d", p->data);
p = p->next;
}
}```

<!-- Rest of the sources -->
429->    <CL Condition="'%(ClCompile.PrecompiledHeader)' != 'Create' and '%(ClCompile.ExcludedFromBuild)'!='true' and '%()' == '' and @(ClCompile) != ''"
BuildingInIDE                      ="\$(BuildingInsideVisualStudio)"
Sources                            ="@(ClComp

得分:5

void initlist(node* q)
{
int i;
struct node* k,*p;
p->data = 0;
k= q->next;
while (i<10)
warning C4700: uninitialized local variable 'p' used
warning C4700: uninitialized local variable 'i' used

得分:0

得分:5

```#include<stdio.h>
#include<stdlib.h>

struct node
{
int data;
struct node* next;
struct node* prior;
};
void initlist(node* p);
void conversion(node* q);
void Printf(node* q);
int main()
{
node* p;
p = (struct  node*)malloc(sizeof(node));
p->next = NULL;
p->prior = NULL;
p->data = -1;
initlist(p);
conversion(p);
//Printf(p);
}
void initlist(node* q)//运行完这个初始化函数，回到main()里面的q,q->next=NULL,q->data=-1,q->prior=NULL   ,这个函数根本就没有起任何作用
{
int i;
struct node* k,*p;//程序运行到这里只是声明了两个指针变量k和p,并未初始化。
p->data = 0;     //在没有给p指针赋值的情况下，p->data是个莫名其妙的东西。所以程序运行之前报error，运行之后就直接狗带了
k= q->next;      //q->next 在main函数里被你初始化为NULL，那么这里为什么不直接k=NULL  ?
while (i<10)
{
struct node*s= (struct  node*)malloc(sizeof(node));
s->data = p->data ++;
s->prior = k;
k->next = s;      //k在while循环之外被定义为NULL了，那么这里的k->next  也是不可取的。NULL->next  ,NULL->data   ,NULL->prior  都是不对的，程序运行时都要狗带的
k = k->next;
s->next = NULL;
}
}

void initlist2(node* q)   //我不清楚你想要的链表初始化效果怎么样，就照最简白的写了一个，希望你能理解其含义，改写成自己需要的
{
for(int i =0;i<10;i++）{
q->next=(struct node*)malloc(sizeof(node));
q->next->data=i;
q->next->prior=q;
q=q->next;
}
q->next=NULL;//最后一个指针的NEXT=NULL
}
}
void conversion(node* q)//这部分就不看了。涉及到指针的代码测试，你可以试着在脑子里模拟程序的运行，去看看每一步的运行结果是否和预期的一致。可以在一些你想不透的地方加printf(),把变量输出看看验证一下你的设想
{
int i;
struct node* p,*s;
s = q->next;
while (s->data !=NULL)
{
if (s->next == NULL)
p = s;
s = s->next;
}
s = q->next;
while (&s !=& p || s->prior != p)
{
s->data = s->data + p->data;
p->data = s->data - p->data;
s->data = s->data - p->data;
p = p->prior;
s = s->next;
}
}

void Printf(node* q)
{
struct node* p;
p = q->next;
while (p->next == NULL)
{
printf("%d", p->data);
p = p->next;
}
}```

φ(゜▽゜*)♪
• 4
• 1/1页
• 1

Powered by Discuz, Processed in 0.054613 second(s), 8 queries.