一道很简单的C语言小题,请在今晚8点前给出答案 速度快者有加分

已知head指向一个带头结点的单向链表,链表中每个结点包含数据域(data)和指针域(next),数据域为整型.请分别编写函数,在链表中查找数据域值最大的结点:
(1)有函数值返回找到最大值.
(2)有函数值返回最大值所在的结点的地址值.
以下是已给出的步骤请补充完整〔从头到尾一个完整的答案,如果有错误也请修改(可能是我打错了).〕
int max (struct TT *p)
{int m;/*最大值*/int *pmax;}x;
p=head->next; m=p->data;pmax=p;/*最大值地址值*/
for(p=p->next;p;p=->next)
if(m<p->data){m=p->data;pmax=p;}
是帮朋友问的我不懂的,请不要骗我呀,朋友说是要什么 宏定义,主函数,和输出. (输出最主要) 会有加分50
没有主函数和输出部分呢.
输出呢????
现在流行回答问题匿名吗? 三楼能做一些简单的讲解吗?

既然你对C语言知之甚少,就直接把这两个函数给你朋友看吧!如果他懂C语言,一定会明白并且满意!

输入输出部分与程序意图和主函数有关,而且十分简单。你朋友一定知道输入输出这么简单的操作的。

**********************************************

题目只要求写出查找函数,没有要求主函数:

“请分别编写函数,在链表中查找数据域值最大的结点”

而且由于不明白具体程序的意图,所以无法写出符合要求的主函数。

**********************************************

函数1,返回最大值:

int max(struct TT *p)
{
int m;
struct TT *p;

p=head->next;
m=p->data;
for(p=p->next;p;p=p->next)
if(m<p->data){m=p->data;}

return m;
}

函数2,返回最大值地址:

struct TT *max(struct TT *p)
{
int m;
struct TT *pmax;
m=p->data;
pmax=p;
for(p=p->next;p;p=p->next)
if(m<p->data){m=p->data;pmax=p;}
return pmax;
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2008-03-21
#include "stdio.h"
#include "stdlib.h"
struct node
{ int data;
struct node *next;
};
struct node *searchmax(struct node *head)
{ struct node *pmaxnode,*pnode;
pnode=head;
pmaxnode=head;
while(pnode!=NULL)
{ if(pnode->data>pmaxnode->data||pmaxnode==NULL);
{ pmaxnode->data=pnode->data;
pmaxnode=pnode;
}
pnode=pnode->next;
}
return pmaxnode;
}
main()
{ struct node *head,*tail,*pnode;
int data;
printf("input data\n Enter Exit to quit\n");
head=tail=NULL;
while(scanf("%d",&data)==1)
{ pnode=(struct node *)malloc(sizeof(struct node));
pnode->data=data;
pnode->next=NULL;
if(head==NULL)
head=tail=pnode;
else
{ tail->next=pnode;
tail=pnode;
}
}
if(head!=NULL)
printf("max is %d\n",searchmax(head)->data);
while(head!=NULL)
{ pnode=head;
head=head->next;
free(pnode);
}
getch();
}
第2个回答  2008-03-21
我不做C语言很多年