想用一段C语言代码在下面这段代码里面增加一段查询图书借阅数量的,
就是查询读者信息中增加查询读者目前可借阅图书的数量
结构体再加一个成员
#include<stdio.h>
#include<stdlib.h>
struct node
{
//指数
int exp;
//系数
float coef;
struct node *next;
};
//简写
typedef struct node Node;
//函数的声明
Node *creatList();
void DisList(Node *head);
int main(int argc, char const *argv[])
{
Node *myNode;
myNode = creatList();
DisList(myNode);
return 0;
}
/**
* 创建多项式链表
* 用户输入多项式每一项的系数和指数,只要二者不同时为0,则一直接收用户输入
* @return Node* 返回创建好的链表的头指针
*/
Node *creatList()
{
Node *previous, *head = NULL, *current;
//指数
int exp;
//系数
float codf;
printf("请输入系数和指数: ");
scanf("%f,%d",&codf,&exp);
while(exp!=0 || codf != 0)
{
current = (Node *) malloc(sizeof(Node));
current->coef = codf;
current->exp = exp;
current->next = NULL;
//如果头指针是空,则把当前结点赋值给头指针
if(head == NULL)
{
head = current;
}
//如果不是头指针,则把当前结点链接在先前结点后面
else
{
previous->next = current;
}
//先前结点变为当前结点
previous = current;
printf("请输入系数和指数: ");
scanf("%f,%d",&codf,&exp);
}
return head;
}
/**
* 多项式链表的遍历
* 输入多项式的每一个元素
* @Node *head, 需要遍历链表的头指针
*/
void DisList(Node *head)
{
Node *p = head;
while(p)
{
printf("%.2f X^%d",p->coef,p->exp);
if(p->next != NULL)
{
printf(" + ");
}
p = p->next;
}
}