⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 51y0qrur.txt

📁 原作者: 这是我学数据结构编写的算法
💻 TXT
📖 第 1 页 / 共 2 页
字号:
{
     CreatTree(point,2);
}

  cout<<"该"<<point->data<<"节点是否有右子树 Y / 任意键 :";
  cin>>temp;
  if(temp=='y'||temp=='Y')
{
  CreatTree(point,3);
}
}

template<class Type>
void BinTree<Type>::PreTree(TreeNode<Type> *point)
{
if(point!=NULL)
{
 cout<<" "<<point->data;
 PreTree(point->lchild);
 PreTree(point->rchild);
}
}


template<class Type>
void BinTree<Type>::InoTree(TreeNode<Type> *point)
{
if(point!=NULL)
{
 
   InoTree(point->lchild);
 cout<<" "<<point->data;
 InoTree(point->rchild);
}
}

template<class Type>
void BinTree<Type>::PosTree(TreeNode<Type> *point)
{
if(point!=NULL)
{
 
 PosTree(point->lchild);
 PosTree(point->rchild);
 cout<<" "<<point->data;
}
}


template<class Type>
bool BinTree<Type>::ISEmpty()
{
return root==NULL;
}

template<class Type>
void BinTree<Type>::Destroy(TreeNode<Type> *point)
{
if(point!=NULL)
{
 Destroy(point->lchild);
 Destroy(point->rchild);
 delete point;
}
}


///////////////////////////
//    //
//  基本功能函数 BaseFun.h   //
//    //
//////////////////////////

void GRAPH();
void LIST();
void STACK();
void QUEUE();
void COMPOSITOR();
void BINTREE();

///////////////////////////
//    //
//   堆栈功能函数   Stack.cpp/ /
//    //
//////////////////////////



#include"Stack.h"
#include"iostream.h"


const int INT =13;
const double FLOAT= 13.33;
const char CHAR ='a';




template<class Type>
void Stack_Push(Stack<Type> &StackOPP)
{
cout<<"请输入要插入的数据项: ";
Type item;
cin>>item;
  StackOPP.Push(item);
}

template<class Type>
void Stack_Pop(Stack<Type> &StackOPP)
{
if(!StackOPP.ISEmpty())
{
   cout<<"出栈数据项: ";
    cout<<StackOPP.Pop()<<endl;
}
else
{
 cout<<"堆栈已经为空!"<<endl;
}
}

template<class Type>
void Stack_ISEmpty(Stack<Type> &StackOPP)
{
if(!StackOPP.ISEmpty())
   cout<<"堆栈不空,还有"<<StackOPP.GetNum()<<"数据项!"<<endl;
else
 cout<<"堆栈为空!"<<endl;
 
}

template<class Type>
void Stack_GetTop(Stack<Type> &StackOPP)
{
if(!StackOPP.ISEmpty())
  cout<<"栈顶元素为:"<<StackOPP.GetTop()<<endl;
else
  cout<<"堆栈为空!"<<endl;
}

template<class Type>
void Stack_MakeEmpty(Stack<Type> &StackOPP)
{
if(!StackOPP.ISEmpty())
{
 StackOPP.MakeEmpty();
 cout<<"堆栈已经销毁!"<<endl;
}
else
{
 cout<<"销毁失败!"<<endl;
}
}


template<class Type>
void StackINI(Type temp)
{
Stack<Type> StackOPP;

do
{
cout<<"堆栈的操作: "<<endl
 <<" 1) 插入堆栈"<<endl
 <<" 2) 出栈"<<endl
 <<" 3) 堆栈是否为空"<<endl
 <<" 4) 得栈顶数据项"<<endl
 <<" 5) 销毁堆栈"<<endl
 <<" X) 退出堆栈操作"<<endl;
int item;
cin>>item;
switch(item)
{
case 1: Stack_Push(StackOPP); break;
case 2: Stack_Pop(StackOPP);  break;
case 3: Stack_ISEmpty(StackOPP);  break;
case 4: Stack_GetTop(StackOPP); break;
case 5: Stack_MakeEmpty(StackOPP); break;

default: return ;
}

}while(true);


}


void STACK()
{
int item;
cout<<"清选择数据类型: 1) 整型 2) 浮点型 3) 字符型 X) 退出: ";

cin>>item;
switch(item)
{
case 1: StackINI(INT); break; //根据不同的用户需要选择数据类型
case 2: StackINI(FLOAT); break;
case 3: StackINI(CHAR); break;
  default: return ; break;
}
}



///////////////////////////
//    //
//   队列功能函数 Queue.h  //
//    //
//////////////////////////
#include"Queue.h"

const int INT =13;
const double FLOAT= 13.33;
const char CHAR ='a';



template<class Type>
void Queue_Enter(Queue<Type> &QueueOPP)
{
cout<<"请输入要插入队列的数据: ";
Type item;
cin>>item;
QueueOPP.EnQueue(item);
}

template<class Type>
void Queue_Del(Queue<Type> &QueueOPP)
{
  if(!QueueOPP.ISEmpty())
  {
  cout<<"出队数据:"<<QueueOPP.DelQueue()<<endl;
  }
  else
  {
  cout<<"队列已为空!"<<endl;
  }
}

template<class Type>
void Queue_ISEmpty(Queue<Type> &QueueOPP)
{
if(QueueOPP.ISEmpty())
{
 cout<<"队列已空!"<<endl;
}
else
{
 cout<<"队列不空!"<<endl;
}
}


template<class Type>
void Queue_GetFront(Queue<Type> &QueueOPP)
{
if(!QueueOPP.ISEmpty())
{
 cout<<"队头元素为: "<<QueueOPP.GetFront()<<endl;
}
else
{
 cout<<"队列已空!"<<endl;
}
}

template<class Type>
void Queue_MakeEmpty(Queue<Type> &QueueOPP)
{
QueueOPP.MakeEmpty();
cout<<"队列清空!"<<endl;
}

template<class Type>
void QueueINI(Type temp)
{
Queue<Type> QueueOPP;

do
{
cout<<"队列的操作: "<<endl
 <<" 1) 插入队列"<<endl
 <<" 2) 出队"<<endl
 <<" 3) 队列是否为空"<<endl
 <<" 4) 得队头数据项"<<endl
 <<" 5) 销毁队列"<<endl
 <<" X) 退出队列操作"<<endl;
int item;
cin>>item;
switch(item)
{
case 1: Queue_Enter(QueueOPP); break;
case 2: Queue_Del(QueueOPP); break;
case 3: Queue_ISEmpty(QueueOPP);  break;
case 4: Queue_GetFront(QueueOPP); break;
case 5: Queue_MakeEmpty(QueueOPP); break;

default: return ;
}

}while(true);


}


void QUEUE()  //根据不同的用户需要选择数据类型
{
int item;
cout<<"清选择数据类型: 1) 整型 2) 浮点型 3) 字符型 X) 退出: ";


cin>>item;
switch(item)
{
case 1: QueueINI(INT); break;
case 2: QueueINI(FLOAT); break;
case 3: QueueINI(CHAR); break;
  default: return ; break;
}
}


///////////////////////////
//    //
//   链表     List.h           //
//    //
//////////////////////////


#include"list.h"
#include<iostream.h>
#include<stdlib.h>


template<class type>
void initlist(type &tmp)
{
  list<type> List;
  int n;

  while(true)
  {

  cout<<"请选择你要对链表进行的操作 "<<endl
  <<"1) 在末尾插入数据"<<endl
   <<"2) 在任意处插入数据"<<endl
  <<"3) 删除数据项"<<endl
  <<"4) 删除整个链表"<<endl
  <<"5) 打印链表"<<endl
  <<"6) 查找数据项"<<endl
  <<"7) 退出"<<endl;

  cout<<">\\ ";
  cin>>n;

  while(n<1||n>7)
  {
 cout<<"输入有误,请从新输入!"<<endl;
   cout<<">\\ ";
   cin>>n;
}

switch(n)
{
case 1: list_insertend(List);break;
case 2: list_insert(List);break;
case 3: list_delnode(List);break;
case 4: list_makeempty(List);break;
case 5: list_print(List);break;
case 6: list_find(List);break;
case 7: return ;break;
}

  }

}

void LIST()
{
int n;
  cout<<"请选择你要构造的链表的数据类型 1)整型,2)字符型,3)浮点型"<<endl;
cout<<">\\ ";
cin>>n;

  while(n<1||n>3)
  {
 cout<<"输入有误,请从新输入!"<<endl;
   cout<<">\\ ";
   cin>>n;
}

char t_c='c';
int t_i=12;
double t_f=23.3;

switch(n)
{
case 1:initlist(t_i);break;
case 2:initlist(t_c);break;
case 3:initlist(t_f);break;
}
}

template<class type>
void list_insertend(list<type> &L)
{
type t;
cout<<"请输入插入数据: >\\";
cin>>t;
L.insertend(t);
}

template<class type>
void list_find(list<type> &L)
{
type T;
cout<<"请输入你要查找的数据项:>\\ ";
cin>>T;

int i;
if(!(i=L.find(T)))
 cout<<"你要查找的数据项不存在!"<<endl;
else
 cout<<"你要查找的数据项在第"<<i<<"个位置"<<endl;
}

template<class type>
void list_insert(list<type> &L)
{

type t;
cout<<"请输入插入数据: >\\";
cin>>t;

int n;
cout<<"请输入插入位置: >\\";
cin>>n;
if(L.insert(t,n))
 cout<<"插入成功! 在"<<n<<"位置 插入"<<t<<endl;
else
 cout<<"插入失败! 插入位置不正确!"<<endl;

}

template<class type>
void list_delnode(list<type>& L)
{
int i;
  cout<<"请输入要删除数据项的位置: >\\";
cin>>i;


while(i<1||i>L.getlen())
{
    cout<<"输入有误,可能大与链表长度,请从新输入!"<<endl;
    cout<<">\\ ";
  cin>>i;
}

L.delnode(i);
}
template<class type>
void list_makeempty(list<type> &L)
{
L.makeempty();
}

template<class type>
void list_print(list<type> &L)
{
if(!L.print())
 cout<<"链表为空!"<<endl;
}


///////////////////////////
//    //
//   图功能函数  Graph.h    //
//    //
//////////////////////////


#include"Graph.h"

template<class NameType,class DisType>
void Graph_Creat(Graph<NameType,DisType> &GraphOPP)
{
GraphOPP.Creat();
}

template<class NameType,class DisType>
void Graph_DFS(Graph<NameType,DisType> &GraphOPP)
{
GraphOPP.DFS();
}

template<class NameType,class DisType>
void Graph_BFS(Graph<NameType,DisType> &GraphOPP)
{
GraphOPP.BFS();
}

template<class NameType,class DisType>
void Graph_PRINT(Graph<NameType,DisType> &GraphOPP)
{
GraphOPP.PrintNode();
}


void GRAPH()
{
Graph<char,int> GraphOPP;
do
{
cout<<"图的操作: "<<endl
 <<" 1) 建立图"<<endl
 <<" 2) 图的深度优先搜索"<<endl
 <<" 3) 图的广度优先搜索"<<endl
 <<" 4) 打印图中各结点"<<endl
 <<" X) 退出排序操作"<<endl;
int item;
cin>>item;
switch(item)
{
case 1: Graph_Creat(GraphOPP); break;
case 2: Graph_DFS(GraphOPP);  break;
case 3: Graph_BFS(GraphOPP);  break;
case 4: Graph_PRINT(GraphOPP);  break;
default: return ;
}

}while(true);


}

///////////////////////////
//    //
//  排序算法功能函数    Compositor.cpp //
//    //
//////////////////////////



#include"Compositor.h"


const int INT =13;
const double FLOAT= 13.33;
const char CHAR ='a';

template<class type>
void CompositorINI(type temp)
{
Compositor<type> CompositorOPP;

do
{
cout<<"排序的操作: "<<endl
 <<" 1) 插入排序"<<endl
 <<" 2) 快速排序"<<endl
 <<" 3) 归并排序"<<endl
 <<" 4) 冒泡排序"<<endl
 <<" 5) 选择排序"<<endl
 <<" X) 退出排序操作"<<endl
 <<"请选择相应的操作: ";
int item;
cin>>item;
switch(item)
{
case 1: Compositor_Insert(CompositorOPP); break;
case 2: Compositor_Quick(CompositorOPP);  break;
case 3: Compositor_Merge(CompositorOPP);  break;
case 4: Compositor_Bubble(CompositorOPP); break;
case 5: Compositor_Select(CompositorOPP); break;

default: return ;
}

}while(true);


}

void COMPOSITOR()//根据不同的用户需要选择数据类型
{
int item;
cout<<"清选择数据类型: 1) 整型 2) 浮点型 3) 字符型 X) 退出: ";


cin>>item;
switch(item)
{
case 1: CompositorINI(INT); break;
case 2: CompositorINI(FLOAT); break;
case 3: CompositorINI(CHAR); break;
  default: return ; break;
}
}

template<class type>
void Compositor_Insert(Compositor<type> CompositorOPP)
{
CompositorOPP.Insert();
}

template<class type>
void Compositor_Quick(Compositor<type> CompositorOPP)
{
CompositorOPP.Quick();
}

template<class type>
void Compositor_Select(Compositor<type> CompositorOPP)
{
CompositorOPP.Select();
}

template<class type>
void Compositor_Merge(Compositor<type> CompositorOPP)
{
CompositorOPP.MergeSort();
}


template<class type>
void Compositor_Bubble(Compositor<type> CompositorOPP)
{
CompositorOPP.Bubble();
}

///////////////////////////
//    //
//   二叉树功能函数 BinTree.cpp//
//    //
//////////////////////////


#include<iostream.h>
#include"BinTree.h"

const int INT =13;
const double FLOAT= 13.33;
const char CHAR ='a';



template<class Type>
void BinTree_CREAT(BinTree<Type>& BinTreeOPP)
{
    BinTreeOPP. CreatTree();
}

template<class Type>
void BinTree_PRE(BinTree<Type>& BinTreeOPP)
{
if(!BinTreeOPP.ISEmpty())
{
   cout<<"先序遍历二叉树 : ";
   BinTreeOPP. PreTree(BinTreeOPP.root);
}
else
{
 cout<<"二叉树已经为空!"<<endl;
}
}

template<class Type>
void BinTree_INO(BinTree<Type>& BinTreeOPP)
{
if(!BinTreeOPP.ISEmpty())
{
   cout<<"中序遍历二叉树 : ";
 BinTreeOPP. InoTree(BinTreeOPP.root);
}
else
{
 cout<<"二叉树已经为空!"<<endl;
}

}

template<class Type>
void BinTree_POS(BinTree<Type>& BinTreeOPP)
{
if(!BinTreeOPP.ISEmpty())
{
 cout<<"后序遍历二叉树 : ";
 BinTreeOPP. PosTree(BinTreeOPP.root);
}
else
{
 cout<<"二叉树已经为空!"<<endl;
}
}

template<class Type>
void BinTree_Destroy(BinTree<Type>& BinTreeOPP)
{
BinTreeOPP.Destroy(BinTreeOPP.root);
BinTreeOPP.root=NULL;
cout<<"二叉树已经销毁!"<<endl;
}

template<class Type>
void BinTree_THREAD(BinTree<Type>& BinTreeOPP)
{
if(BinTreeOPP.ISThread())
{
 cout<<"该二叉树已经线索化!!"<<endl;
}
else
{
 BinTreeOPP.ThreadTree();
}
}

template<class Type>
void BinTree_THROUGH(BinTree<Type>& BinTreeOPP)
{
 BinTreeOPP.Through();
}


template<class Type>
void BinTreeINI(Type temp)
{
BinTree<Type> BinTreeOPP;

do
{
cout<<"树的操作: "<<endl
 <<" 1) 构造二叉数"<<endl
 <<" 2) 先序遍历二叉树"<<endl
 <<" 3) 中序遍历二叉树"<<endl
 <<" 4) 后序遍历二叉树"<<endl
 <<" 5) 销毁二叉树  "<<endl
 <<" X) 退出二叉树操作"<<endl;
int item;
cin>>item;
switch(item)
{
case 1: BinTree_CREAT(BinTreeOPP); break; //构造二叉数
case 2: BinTree_PRE(BinTreeOPP);  break; //先序遍历二叉树
case 3: BinTree_INO(BinTreeOPP); break;  //中序遍历二叉树
  case 4: BinTree_POS(BinTreeOPP); break;   //后序遍历二叉树
  case 5: BinTree_Destroy(BinTreeOPP);break;   //求树的深度
default: return ;
}

}while(true);


}

void BINTREE()
{
int item;
cout<<"清选择数据类型: 1) 整型 2) 浮点型 3) 字符型 X) 退出: ";


cin>>item;
switch(item)
{
case 1: BinTreeINI(INT); break; //根据不同的用户需要选择数据类型
case 2: BinTreeINI(FLOAT); break;
case 3: BinTreeINI(CHAR); break;
  default: return ; break;
}
}


///////////////////////////
//    //
//   主函数 index.cpp  用户菜单 //
//    //
//////////////////////////


#include <iostream.h>
#include"BaseFun.h"

void main()
{
//功能菜单
do
{
cout<<"欢迎使用数据结构算法集"<<endl
 <<"1) 线性表 "<<endl
 <<"2) 堆栈 "<<endl
 <<"3) 队列 "<<endl
 <<"4) 二叉树 "<<endl
 <<"5) 图 "<<endl
 <<"6) 排序算法 "<<endl
 <<"7) 字符串 "<<endl
 <<"X) 按任意键退出 "<<endl;
  cout<<" 请您选择何种数据结构的操作:"<<endl;
int kind;
cin>>kind;
switch(kind)
{
case 1: LIST(); break;
case 2: STACK(); break;
case 3: QUEUE(); break;
case 4: BINTREE(); break;
case 5: GRAPH(); break;
case 6: COMPOSITOR(); break;
default: return;
}
}while(true);

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -