注册 登录
编程论坛 数据结构与算法

superman gives me help

迢迢菜 发布于 2014-04-02 19:56, 512 次点击
输入多项式的系数与指数
#include<stdio.h>
#include<malloc.h>
#define null 0
typedef struct node{
float coef;
int exp;
struct node *next;
}polynode;
polynode* creatpolyn(polynode *L)
{
    polynode *head,*p,*s;
    int m,i;
    head=(polynode*)malloc(sizeof(polynode));
    head->exp=-1;
    head->next=null;
    p=head;
    printf("多项式的项的个数m:");
    scanf("%d",&m);
    printf("请以(系数,指数)方式依次输入\n");
    for(i=1;i<=m;i++)
    {s=(polynode*)malloc(sizeof(polynode));
     scanf("(%f,%d)",&s->coef,&s->exp);
     p->next=s;
     p=s;
    }
    p->next=null;
    return (head);
}
int main()
{
    polynode *L,*l;
    L=creatpolyn(L);
    l=L->next;
    printf("%fx(%d)",l->coef,l->exp);
    l=l->next;
    while(l!=null){
        printf("+%fx(%d)",(l++)->coef,(l++)->exp);
    }
}
没语法错误,怎么运行时就是出问题
1 回复
#2
迢迢菜2014-04-02 23:11
就是无法创建一个链表
1