数据结构课程设计-二叉树操作系统

二叉树操作系统(辅助头文件)部分:
第一部分:队列
#define MAX 10000
typedef struct              //既然顺序队列的话,那么一个这种结构类型的节点就好了---想想是不是   
{
    BTree data[MAX];     
    int front;               
	int rear;
	int tag;
}SqQueue,*Squeue;               

void Init_Squeue(Squeue &head)     //额,顺序队列,你居然还要创建节点,汗...
{
	head=(Squeue)malloc(sizeof(SqQueue));
	head->front=0;          //不舍弃内存单元的初始设置 
	head->rear=0;
	head->tag=0;       //q.front==q.rear&&tag!=0   那只能是满的状态  
}                        

int Empty_Squeue(SqQueue head)           //判满和判空要单独写函数吗,其实不需要的,毕竟都只是一行代码就解决了 
{
	if(head.rear==head.front&&head.tag==0)
		return 1;
	return 0;
}

int Full_Squeue(SqQueue head)             //不过分开来还是比较好
{	
	if(head.front==head.rear&&head.tag==1)
		return 1;
	return 0;
}

void En_Squeue(Squeue head,BTree e)       //入队时要判断是否已满
{
	if(Full_Squeue(*head))
	{
		printf("对不起,当前顺序队列在插入第%d个元素后已满,无法插入更多的元素!!!\n",MAX);
		return ;
	}
	head->data[head->rear]=e;
	head->rear=(head->rear+1)%MAX;
	head->tag=1;     
}

void De_Squeue(Squeue head,BTree *e)    //出队时要判断是否已空  
{
	if(Empty_Squeue(*head))
	{
		printf("对不起,当前队列是空的,无法完成出队操作!!!\n");
		return ;
	}                            //我们通过控制整形front以及rear来近似做到出队操作,实际上没有删除该数据元素  
	*e=head->data[head->front];
	head->front=(head->front+1)%MAX;     //加1取余就实现了循环操作 
	head->tag=0;
	return ;
}
第二部分:栈
#define SUCCESS 0
#define IS_ROOT -1
#define IS_LEAF -2
#define PARAMETER_ERR -3
#define ERROR 0

typedef struct BTNode                //左右孩子表示法---二叉链表
{
	DataType data;
	ElemType ans;
	struct BTNode *lchild;                     //二叉树的链式存储结构
	struct BTNode *rchild;
}BTNode,*BTree;

#define MaxStackSize 10000
typedef struct
{
	BTree data[MaxStackSize];
	int top;
}SqStack;

void StackInitiate(SqStack *S)
{
	S->top=0;
}

int StackNotEmpty(SqStack S)
{
	if(S.top<=0) 
		return 0;
	else
		return 1;
}

int StackPush(SqStack *S,BTree x)
{
	if(S->top>=MaxStackSize)
	{
		printf("堆栈已满无法插入!!!\n");
		return 0;
	}
	else
	{
		S->data[S->top]=x;
		S->top++;
		return 1;
	}
}

int StackPop(SqStack *S,BTree *d)
{
	if(S->top<=0)
	{
		printf("堆栈已空无数据元素出栈!\n");
		return 0;
	}
	else
	{
		S->top--;
		*d=S->data[S->top];
		return 1;
	}
}
二叉树操作系统(源文件部分):
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<limits>
#include<bitset>
#include<string>
#include<vector>
#include<time.h>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include<ctype.h>
#include<conio.h>
#include<iostream>
#include<string.h>
#include<stdlib.h>
#include<malloc.h>
#include<windows.h>
#include<algorithm>
using namespace std;
typedef int ElemType;
typedef char DataType;
#include"SqStack.h"
#include"SqQueue.h"
#include"二叉树基本操作.h"
#include"二叉排序树.h"
#include"哈夫曼树.h"
int main()
{
	BTree root=NULL;
	int chioce;
	system("mode con:cols=400 lines=30000");        ///调节控制台的宽度和高度
	system("color 0b");      ///调节控制台的背景和字体颜色
point1:
	Delay("\t\t\t\t\t\t\t\t\3\3\3\3\3\3\3\3\3\3\3\3\3欢迎你使用二叉树操作系统\3\3\3\3\3\3\3\3\3\3\3\3\3\3\n");
	printf("请输入你想要实现的功能:1、二叉树的基本操作  2、二叉树的基本应用\n");
    scanf("%d",&chioce);
    if(chioce==1)
        Basic_operation(root);
    else
	{
		system("cls");
		printf("\t\t\t\t\t\t 二叉树的基本应用\n");
		printf("\t\t\t\t\t\t1、二叉排序树应用\n");
		printf("\t\t\t\t\t\t2、最优二叉树应用\n");
		printf("提示:非选项数退出当前操作!!!\n");
		printf("请输入所需要进行的应用编号: \n");
		scanf("%d",&chioce);
		if(chioce==1)
			Fuction_BTree(root);
		else if(chioce==2)
			Fuction_HuffumanTree(root);
	}
	system("cls");
	goto point1;
	return 0;
}写的不好,大牛们请谅解哈~  毕竟我是小白!本来想附上相关图片的,发现我不会,嘿嘿~
 

  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值