关于链表!

来源:百度知道 编辑:UC知道 时间:2024/05/12 15:08:52
#include "stdlib.h"
#include "stdio.h"
struct node
{int data;
struct node *next;};

struct node *creat()
{struct node *H,*r,*p;
int a;
H=(struct node *)malloc(sizeof(struct node));
r=H;
scanf("%d",&a);
while(a!=0)
{p=(struct node *)malloc(sizeof(struct node));
r->next=p;
p->data=a;
r=p;
scanf("%d",&a);}
r->next=NULL;
return(H);}

struct node *adjmax(struct node *H)
{struct node *p,*q,*pp;
int max=0;
p=H->next;
if(p==NULL)
return(p);
else if(p->next==NULL)
return(p->next);
else
{q=p->next;
pp=p;
max=p->data+q->data;}
while(q->next)
{p=q;
q=q->next;
if(p->data+q->data>max)
pp=p;}
return(pp);}

main()
{struct node *H,*p,*q;
char b;
con: H=creat();

在屏幕输入变量前要清空缓存哦!


b=getchar();
这一句前面添加以下语句即可:

fflush(stdin); //刷新标准输入缓冲区,把输入缓冲区里的东西丢弃

已调试