Binary Sorting Tree_Cosmetics_v1.0
来源:互联网 发布:数据库管理器 编辑:程序博客网 时间:2024/06/07 06:47
#include<stdio.h>
#include<stdlib.h>
typedef int datatype;
typedef struct node
{
char brand[20];
datatype pride;
struct node *lchild, *rchild;
}bsnode;
typedef bsnode *bstree;
void bssearch(bstree t, datatype x, bstree *f, bstree *p)
{
*f = NULL;
*p = t;
while (*p)
{
if (x == (*p)->pride)
return;
*f = *p;
*p = (x < (*p)->pride ? (*p)->lchild : (*p)->rchild);
}
}
void InsertBstree(bstree *t, datatype x,char b[])
{
bstree f = NULL, p;
int i;
p = *t;
while (p)
{
if (x == p->pride)
return;
f = p;
p = (x < p->pride) ? p->lchild : p->rchild;
}
p = (bstree)malloc(sizeof(bsnode));
p->pride = x;
for (i = 0; b[i] != '\0'; i++)
p->brand[i] = b[i];
p->brand[i] = '\0';
p->lchild = p->rchild = NULL;
if (*t == NULL)
*t = p;
else
if (x < f->pride)
f->lchild = p;
else
f->rchild = p;
}
bstree CreatBstree(bstree t)
{
char b[20];
datatype pr;
printf("输入品牌:");
scanf_s("%s", b, 20);
printf("输入%s价格:",b);
scanf_s("%d", &pr, 20);
InsertBstree(&t, pr, b);
return t;
}
void inorder(bstree t)
{
int i = 1;
if (t)
{
inorder(t->lchild);
printf("%s-%d\n",t->brand, t->pride);
inorder(t->rchild);
}
}
void main()
{
bstree t = NULL;
int a,i;
printf("您要输入几条数据:");
scanf_s("%d", &a, 1);
for(i=0;i<a;i++)
t = CreatBstree(t);
printf("********************************\n");
inorder(t);
printf("********************************\n");
}
#include<stdlib.h>
typedef int datatype;
typedef struct node
{
char brand[20];
datatype pride;
struct node *lchild, *rchild;
}bsnode;
typedef bsnode *bstree;
void bssearch(bstree t, datatype x, bstree *f, bstree *p)
{
*f = NULL;
*p = t;
while (*p)
{
if (x == (*p)->pride)
return;
*f = *p;
*p = (x < (*p)->pride ? (*p)->lchild : (*p)->rchild);
}
}
void InsertBstree(bstree *t, datatype x,char b[])
{
bstree f = NULL, p;
int i;
p = *t;
while (p)
{
if (x == p->pride)
return;
f = p;
p = (x < p->pride) ? p->lchild : p->rchild;
}
p = (bstree)malloc(sizeof(bsnode));
p->pride = x;
for (i = 0; b[i] != '\0'; i++)
p->brand[i] = b[i];
p->brand[i] = '\0';
p->lchild = p->rchild = NULL;
if (*t == NULL)
*t = p;
else
if (x < f->pride)
f->lchild = p;
else
f->rchild = p;
}
bstree CreatBstree(bstree t)
{
char b[20];
datatype pr;
printf("输入品牌:");
scanf_s("%s", b, 20);
printf("输入%s价格:",b);
scanf_s("%d", &pr, 20);
InsertBstree(&t, pr, b);
return t;
}
void inorder(bstree t)
{
int i = 1;
if (t)
{
inorder(t->lchild);
printf("%s-%d\n",t->brand, t->pride);
inorder(t->rchild);
}
}
void main()
{
bstree t = NULL;
int a,i;
printf("您要输入几条数据:");
scanf_s("%d", &a, 1);
for(i=0;i<a;i++)
t = CreatBstree(t);
printf("********************************\n");
inorder(t);
printf("********************************\n");
}
阅读全文
0 0
- Binary Sorting Tree_Cosmetics_v1.0
- Internal Sorting: Binary insertion: Sorting by Insertion
- Sorting
- Sorting:
- Sorting
- Sorting
- Sorting
- Sorting
- Sorting
- 二分搜索树排序binary search sorting的c++实现
- 【内部排序】二:折半插入排序(binary insertion sorting)实现(源码)
- GridView sorting
- java sorting
- java sorting
- insert-sorting
- DNA Sorting
- DNA Sorting
- Sorting Algorithms
- JS对多维数组排序
- Python lambda介绍
- JS返回浏览器历史第一页
- 指针的本质分析
- 蓝绿部署、红黑部署、AB测试、灰度发布、金丝雀发布、滚动发布的概念与区别
- Binary Sorting Tree_Cosmetics_v1.0
- 处理机调度算法
- JavaWeb学习笔记-XML-8
- 171127 Linux tensorboard
- Java与JNI类型转换,方法调用
- # 与 $ 区别以及 sql 预编译
- SVM中的训练算法:序列最小最优化算法SMO的读书笔记
- code forces Help Vasilisa the Wise 2
- LeetCode 分类练习(5)—— 链表相关习题(1)