百度脑图在哪:C语言程序问题请教高手

来源:百度文库 编辑:神马品牌网 时间:2024/04/27 16:02:16
#define NULL 0 //定义符号常量NULL
#define LENG sizeof(struct Lnode) //结点所占的单元数
struct Lnode //定义结点类型
{ int data; //data为整型
struct node *next; //next为指针类型
};
struct Lnode *creat1( )
{ struct Lnode *head,*tail,*p; //变量说明
int e;
head=(struct Lnode *)malloc(LENG); //生成表头结点
tail=head; //尾指针指向表头
do{ p=(struct Lnode *)malloc(LENG);//生成新结点
scanf(“%d”,&e); //输入一个数
p->data=e; //装入输入的元素e
tail->next=p; //新结点链接到表尾
tail=p; //尾指针指向新结点
}
while (e!=0); //不为0
tail->next=NULL; //尾结点的next置为空指针
return head; //返回头指针
}
void link_1ist (struct node *p )
{ whi1e (P->next! = NULL )

{ printf(“%c”, p->data );
p = p->next;}
printf(“\n”);
}
int ListLength_L (LinkList L, int *max, int *min)
//L为链表的头指针, k求长度
{ p=L;k=0;*min=*max = p→data;
while ( p )
{k = k+1;
if(p→data >*max) *max = p→data ;
if(p→data <*min) *min = p→data ;
k++; p = p→next;}

return ( k );
}

main ()
{ char ch;int k;float max,min;
struct node *q, *p;
p=creat1( );
link_1ist(p);
k=ListLength_L(p, &max, &min)
printf("max=%d min=%d k=%d",max,min,k);

}
在线等待

#include<stdio.h>
#include<malloc.h>
typedef struct Lnode //定义结点类型
{
int data; //data为整型
struct Lnode *next; //next为指针类型
}*ListNode;
void creat1(ListNode* L )
{
struct Lnode *head,*tail,*p; //变量说明
int e;
head=NULL;
tail=NULL;
p=NULL;
scanf("%d",&e);
if(!e){*L=NULL;return;}
head=(struct Lnode *)malloc(sizeof(struct Lnode)); //生成表头结点
if(!head)return;//申请内存没有成功
head->next=NULL;
tail=head; //尾指针指向表头
head->data=e;
do{
scanf("%d",&e); //输入一个数
if(!e)
{
*L=head;
return;
}
p=(struct Lnode *)malloc(sizeof(struct Lnode));//生成新结点
if(!p)return;
p->next=NULL;
p->data=e; //装入输入的元素e
tail->next=p; //新结点链接到表尾
tail=p; //尾指针指向新结点
} while (1);//不为0
*L=head; //返回头指针
}
void link_1ist (struct Lnode *p )
{

while (p)
{
printf("%d ", p->data );
p=p->next;
}
printf("\n");
}
int ListLength_L (struct Lnode *L, int *max, int *min)
//L为链表的头指针, k求长度
{
int k=0;
*min=*max = L->data;
while (L)
{
if(L->data>*max) *max = L->data ;
if(L->data<*min) *min = L->data ;
k++;
L = L->next;
}

return k ;
}

void main ()
{
int k,max,min;
struct Lnode *p;
p=NULL;
creat1(&p );
link_1ist(p);
k=ListLength_L(p, &max, &min);
printf("max=%d min=%d k=%d",max,min,k);

}
你的错也太多了..这个我调试过了..

你的程序错误太多了
最明显的输入法就错了 你的分号和双引号都是在汉字下输入的 你自己看看吧
另外结构体申明也有问题 类型转换不匹配。。。
自己仔细看看吧
你这个程序是根据链表改的吧? 再仔细看看

你需要解决的问题是什么呀?

你0分悬赏什么啊?