l8.cpp
来自「这里面包括数据结构多数的算法」· C++ 代码 · 共 78 行
CPP
78 行
#include <stdio.h>
#include <stdlib.h>
typedef int InfoType;
typedef int KeyType; //假定关键字类型为整数
typedef struct node //结点类型
{
KeyType key; //关键字项
InfoType otherinfo; //其它数据域,InfoType视应用情况而定 下面不处理它
struct node *lchild,*rchild;//左右孩子指针
}BSTNode;
typedef BSTNode *BSTree; //BSTree是二叉排序树的类型
void main()
{
void InsertBST(BSTree *Tptr,KeyType key); //将关键字key插入二叉排序树中
BSTree CreateBST(void); //建立二叉排序树
void ListBinTree(BSTree T); //用广义表表示二叉树
void DelBSTNode(BSTree *Tptr,KeyType key); //在二叉排序树中删除关键字key
BSTNode *SearchBST(BSTree T,KeyType key); //在二叉排序树中查找关键字key
BSTree T;
BSTNode *p;
int key;
printf("请输入关键字(输入0为结束标志):\n");
T=CreateBST();
ListBinTree(T);
printf("\n");
printf("请输入欲插入关键字:");
scanf("%d",&key);
InsertBST(&T,key);
ListBinTree(T);
printf("\n");
printf("请输入欲删除关键字:");
scanf("%d",&key);
DelBSTNode(&T,key);
ListBinTree(T);
printf("\n");
printf("请输入欲查找关键字:");
scanf("%d",&key);
p=SearchBST(T,key);
if(p==NULL)
printf("没有找到%d!\n",key);
else
printf("找到%d!\n",key);
ListBinTree(p);
printf("\n");
}
//将关键字key插入二叉排序树中
void InsertBST(BSTree *Tptr,KeyType key)
{
//在此插入必要的语句
}
//建立二叉排序树
BSTree CreateBST(void)
{
//在此插入必要的语句
}
//在二叉排序树中删除关键字key
void DelBSTNode(BSTree *Tptr,KeyType key)
{
//在此插入必要的语句
}
//用广义表表示二叉树
void ListBinTree(BSTree T)
{
//在此插入必要的语句
}
//在二叉排序树中查找关键字key
BSTNode *SearchBST(BSTree T,KeyType key)
{
//在此插入必要的语句
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?