|
|
|
@ -194,3 +194,54 @@ void delete_data()
|
|
|
|
|
printf("没有找到编号为%d的图书!\n", id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 对图书信息进行排序
|
|
|
|
|
void sort_data()
|
|
|
|
|
{
|
|
|
|
|
struct book *p, *q; // 两节点指针
|
|
|
|
|
struct book temp; // 临时图书结构体
|
|
|
|
|
|
|
|
|
|
p = books;
|
|
|
|
|
while(p != NULL)
|
|
|
|
|
{
|
|
|
|
|
q = p->next;
|
|
|
|
|
while(q != NULL)
|
|
|
|
|
{
|
|
|
|
|
if(p->id > q->id) // 交换节点
|
|
|
|
|
{
|
|
|
|
|
temp = *p;
|
|
|
|
|
*p = *q;
|
|
|
|
|
*q = temp;
|
|
|
|
|
}
|
|
|
|
|
q = q->next;
|
|
|
|
|
}
|
|
|
|
|
p = p->next;
|
|
|
|
|
}
|
|
|
|
|
printf("图书信息排序成功!\n");
|
|
|
|
|
}
|
|
|
|
|
// 生成图表报表
|
|
|
|
|
void make_chart()
|
|
|
|
|
{
|
|
|
|
|
struct book *p;
|
|
|
|
|
char name[20];
|
|
|
|
|
int i, n;
|
|
|
|
|
float price;
|
|
|
|
|
|
|
|
|
|
printf("请输入要生成的图书数量:");
|
|
|
|
|
scanf("%d", &n);
|
|
|
|
|
|
|
|
|
|
for(i=1; i<=n; i++)
|
|
|
|
|
{
|
|
|
|
|
p = (struct book*)malloc(sizeof(struct book));
|
|
|
|
|
|
|
|
|
|
sprintf(name, "图书%d", i); // 生成图书名称
|
|
|
|
|
p->id = i; // 图书编号
|
|
|
|
|
strcpy(p->name, name); // 图书名称
|
|
|
|
|
strcpy(p->author, "作者"); // 作者
|
|
|
|
|
price = (i+1)*10.0; // 价格
|
|
|
|
|
p->price = price; // 图书价格
|
|
|
|
|
|
|
|
|
|
p->next = books; // 新节点指向原链表头
|
|
|
|
|
books = p; // 新节点成为链表头
|
|
|
|
|
}
|
|
|
|
|
printf("随机图书信息生成成功!\n");
|
|
|
|
|
}
|