#include <stdio.h> #include <conio.h> #include <stdlib.h> typedef struct aa {int data; struct aa *next; }NODE; fun(NODE *h) {int max=-1; NODE *p; p=h; while(p) {if(p->data>max) max=p->dat; p=h->next; } return max; } outresult(int s,FILE *pf) {fprintf(pf,"\nThe max in link:%d\n",s);} NODE *creatlink(int n,int m) {NODE *h,*p,*s,*q; int i,x; h=p=(NODE*)malloc(sizeof(NODE));h->data=9999; for(i=1;i<=n;i++) {s=(NODE*)malloc(sizeof(NODE)); s->data=rand()%m;s->next=p->next; p->next=s; p=p->next; } p->next=NULL; return h; } outlink(NODE *h,FILE *pf) {NODE *p; p=p->next; fprintf(pf,"\nTHE LIST:\n\n HEAD"); while(p) {fprintf(pf,"->%d",p->data);p=p->next;} fprintf(pf,"\n"); main() {NODE *head;int m; clrscr(); head=creatlink(12,100); outlink(head,stdout); m=fun(head); printf("\nTHE RESULT:\n");outresult(m,stdout); }
1.在creatlink函数中,p->next还没有赋初值,却有“s->next=p->next;”,p->next指向谁还不确定啊? 2.主函数中,“ outlink(head,stdout);”,stdout是什么?如果是变量的话怎么还没有定义就使用了?