曾经在数据结构的时候做过的实验,最近忽然发现了这个程序,闲来无事就发到网上吧。///创建一个由多张化妆品品牌价格组成的二叉排序树,并按照价格从低到高的顺序打印输出
///定义二叉排序树链表的结点结构
///依次输入各类化妆品品牌的价格并按二叉排序树的要求创建一个二叉排序树链表
///对二叉排序树进行中序遍历输出,打印按价格从低到高顺序排列的化妆品品牌信息
///system("color 16进制16进制");第一个16进制数表示背景色,第二个表示前景色
///0 1 2 3 4 5 6 7 8 9 a b c d e f
///黑 蓝 绿 湖蓝 红 紫 黄 白 灰 淡蓝 淡绿 淡浅绿 淡红 淡紫 淡黄 亮白
#include
{
char name[20];
//名称
float price;
//价格
char productor[50];
//生产商
char pdate[15];
//生产日期
int day;
//有效天数
char fuction[200];
//化妆品功能,暂未添加
struct node *lchild;
struct node *rchild;
}
toiletry;
toiletry *typein(toiletry *t);
///插入操作
void inorder(toiletry *t);
///中序遍历输出
toiletry *del(toiletry *t);
///删除某个化妆品的信息
void error();
///输入错误处理
struct tm *newtime;
char tmpbuf[128];
time_t lt1;
int main()
{
toiletry *head=NULL;
int n;
while(1)
{
system("cls");
///刷新
system("color 0e");
time( <1 );
newtime=localtime(<1);
strftime( tmpbuf, 128, " 今天: %Y %m月%d日 %Ann", newtime);
printf(tmpbuf);
printf("n 欢迎使用化妆品系统nn");
printf(" ☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆n");
printf(" ☆ 【1】 化妆品信息输入 ☆n");
printf(" ☆ 【2】 化妆品信息输出 ☆n");
printf(" ☆ 【3】 化妆品信息删除 ☆n");
printf(" ☆ 【0】 退出 ☆n");
printf(" ☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆n");
scanf("%d", &n);
if(n==1) head=typein(head);
else if(n==2) inorder(head);
else if(n==3) head=del(head);
else if(n==0) break;
else error();
}
system("cls");
system("color 02");
printf("n * *谢谢使用* *n");
}
toiletry *typein(toiletry *t)
{
toiletry *f, *q, *p=(toiletry *)malloc(sizeof(toiletry));
p->lchild=p->rchild=NULL;
char na[20], pro[50], pdate[15];
float price;
int day, k=1;
system("cls");
system("color 0f");
time( <1 );
newtime=localtime(<1);
strftime( tmpbuf, 128, " 今天: %Y %m月%d日 %Ann", newtime);
printf(tmpbuf);
printf(" ☆☆☆☆☆现在开始插入操作☆☆☆☆☆nn");
printf(" 请输入化妆品的信息:名称,价格,生产商,生产日期,有效天数:n");
q=t;
scanf("%s %f %s %s %d", p->name, &p->price, p->productor, p->pdate, &p->day);
while(q)
{
if(p->price==q->price)
{
k=0;
break;
}
f=q;
q=(p->price
版权属于:
加速器之家
作品采用:
《
署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)
》许可协议授权
评论