小弟最近做课程设计 银行财务实时处理系统(二叉排序树的应用) 用c++实现 利用C++,设计程序,定义二叉链表,存储二叉排序树,声明并定...

\u5728c++\u5b9e\u73b0\u4e8c\u53c9\u6392\u5e8f\u6811\u67e5\u627e\u4e2d\u51fa\u73b0\u8fd9\u79cd\u60c5\u51b5\u662f\u600e\u4e48\u56de\u4e8b\uff1f

\u7b80\u5355\u6765\u8bb2\uff0c\u4f60\u7684insert\u51fd\u6570\u53ea\u662f\u628a\u6570\u9001\u5230\u4e86\u90a3\u4e2a\u53f6\u8282\u70b9\u7684\u4f4d\u7f6e\uff0c\u4f46\u662f\u90a3\u91cc\u672c\u6765\u5c31\u662f\u7a7a\u7684\uff0c\u4f60\u5e94\u8be5new\u4e00\u4e2a\u8282\u70b9\u7136\u540e\u628a\u6570\u5b57\u653e\u5728\u90a3\u91cc\uff0c\u7136\u540e\u628a\u8fd9\u4e2a\u65b0\u7684\u8282\u70b9\u548c\u539f\u6709\u7684\u8282\u70b9\u8fde\u63a5\u4e0a

2 \u4ee3\u7801\uff1a 1 \uff09\u4e8c\u53c9\u6392\u5e8f\u6811\uff1a #include"BSTreeNode.h" #include"seqstack.h" #define Max(x1,x2) (x1>x2?x1:x2) //\u8fd4\u56de\u4e24\u4e2a\u6570\u4e2d\u7684\u6700\u5927\u8005 #include using namespace std; template class BSTree { private: //void destory(BSTreeNode *p);//\u5220\u9664\u4ee5p\u4e3a\u6839\u7684\u4e8c\u53c9\u6811 void InOrder(BSTreeNode *r);//\u79c1\u6709\u51fd\u6570\uff1a\u6b64\u7b97\u6cd5\u6309\u7167\u4e2d\u5e8f\u6b21\u5e8f\u904d\u5386\u4e8c\u53c9\u6811 void PostOrder(BSTreeNode *r);//\u79c1\u6709\u51fd\u6570\uff1a\u6b64\u7b97\u6cd5\u6309\u7167\u540e\u5e8f\u6b21\u5e8f\u904d\u5386\u4e8c\u53c9\u6811 int Depth(const BSTreeNode *r); //\u79c1\u6709\u51fd\u6570\uff1a\u6b64\u7b97\u6cd5\u8ba1\u7b97\u4e8c\u53c9\u6811\u7684\u6df1\u5ea6 int LeafSize(const BSTreeNode *r); //\u79c1\u6709\u51fd\u6570\uff1a\u6b64\u7b97\u6cd5\u8ba1\u7b97\u4e8c\u53c9\u6811\u7684\u53f6\u5b50\u7ed3\u70b9\u4e2a\u6570 //void CreatPreThreed(BSTreeNode *&r); BSTreeNode*Find(const Type &k,BSTreeNode*p)const; void Insert(const Type &x,BSTreeNode*&p); void Delete(const Type &k,BSTreeNode*&p); BSTreeNode*& Min(BSTreeNode*&p); BSTreeNode *root; public: BSTree():root(NULL){} BSTreeNode *Root(){return root;} int Depth(); //\u8ba1\u7b97\u4e8c\u53c9\u6811\u7684\u6df1\u5ea6 int LeafSize(); //\u8ba1\u7b97\u4e8c\u53c9\u6811\u7684\u53f6\u5b50\u7ed3\u70b9\u4e2a\u6570 void PreOrder();//\u7528\u6808\u5148\u5e8f\u904d\u5386\u4e8c\u53c9\u6811 void CreatPreThreed(){CreatPreThreed(root);} void InOrder(); void PostOrder(); BSTreeNode *Find(const Type &k)const{return Find(k,root);} //BSTreeNode*& Min(){Min(BSTreeNode*&p);}; //Type Max(); void Insret(const Type &x){Insert(x,root);} void Delete(const Type &k){Delete(k,root);} void CreatBSTree(); }; template void BSTree::InOrder(BSTreeNode *r) { if(r!=NULL) { InOrder(r->GetLeftChild()); coutGetLeftChild()); PostOrder(r->GetRightChild()); coutleftChild == NULL && t->rightChild == NULL) return 1; else return LeafSize(t->leftChild)+LeafSize(t->rightChild); } template int BSTree::Depth() { return Depth(root); } template int BSTree::Depth(const BSTreeNode* t) { if(t==NULL) return 0; //\u9012\u5f52\u7ed3\u675f\u6761\u4ef6\uff1a\u7a7a\u6811\u6df1\u5ea6\u4e3a return 1+Max(Depth(t->leftChild),Depth(t->rightChild)); } template void BSTree::PreOrder() { seqstack *> s(50); if(root==NULL) coutGetRightChild(); } }while(s.empty()!=1||p!=NULL); } /*template void BSTree::CreatPreThreed(BSTreeNode *&r) { Type ch; cin>>ch; if(ch=='#')return; r=new BinTreeNode(ch,NULL,NULL); CreatPreThreed(r->leftChild); CreatPreThreed(r->rightChild); }*/ template void BSTree::InOrder() { InOrder(root); } template void BSTree::PostOrder() { PostOrder(root); }/* template BSTreeNode* BSTree::Find(const Type &k,BSTree*p)const { if(p==NULL) return NULL; else if\uff08kdata\uff09 return Find(k,p->leftChild); else if(k>p->data) return Find(k,p->rightChild); else return p; }*/ template BSTreeNode *BSTree::Find(const Type &k,BSTreeNode*p)const//\u5728p\u4e3a\u6839\u7684\u4e8c\u53c9\u6392\u5e8f\u6811\u4e0a\u8fdb\u884c\u67e5\u627e\u7684\u8fed\u4ee3\u7b97\u6cd5 { BSTreeNode*temp=p; if(p!=NULL) { while(temp!=NULL) { if(temp->data==k) return temp;//\u67e5\u627e\u6210\u529f if(temp->datarightChild;//\u67e5\u627e\u53f3\u5b50\u6811 else temp=temp->leftChild;//\u67e5\u627e\u5de6\u5b50\u6811 } } return temp;//\u67e5\u627e\u5931\u8d25 } template void BSTree::Insert(const Type &x,BSTreeNode*&p)//\u5728p\u4e3a\u6839\u7684\u4e8c\u53c9\u6392\u5e8f\u6811\u4e0a\u63d2\u5165\u7ed3\u70b9\u7684\u9012\u5f52\u7b97\u6cd5 { if(p==NULL)//\u7a7a\u4e8c\u53c9\u6811 p=new BSTreeNode(x);//\u521b\u5efa\u6570\u636e\u5143\u7d20x\u7684\u7ed3\u70b9 else if(xdata) Insert(x,p->leftChild);//\u5728\u5de6\u5b50\u6811\u63d2\u5165 else if(x>p->data) Insert(x,p->rightChild);//\u5728\u53f3\u5b50\u6811\u63d2\u5165 else //\u7ed3\u70b9x\u5b58\u5728 { coutp->data) //delete(k,p->rightChild); Delete(k,p->rightChild);//\u82e5p\u7684\u5173\u952e\u5b57\u5c0f\u4e8ek\uff0c\u5219\u5728p\u7684\u53f3\u5b50\u6811\u5220\u9664 else if(p->leftChild!=NULL&&p->rightChild!=NULL) { /* temp=Min(p->rightChild); p->data=temp->data; delete(p->data,temp); */ BSTreeNode *&temp1=Min(p->rightChild); p->data=temp1->data; Delete(p->data,temp1); //\u6ce8\u610f\u8fd9\u91cc\u548c\u4f60\u539f\u6765\u7684\u6bd4\u8f83\u662fDelete\u800c\u975edelete } else { temp=p; if(p->leftChild==NULL) p=p->rightChild; else if(p->rightChild==NULL) p=p->leftChild; delete temp; } } templatevoid BSTree::CreatBSTree() { int i(0); coutch; if(ch!=-1) { Insert(ch,root); i++; } else break; } } //template templateBSTreeNode*& BSTree::Min(BSTreeNode *&p) { /* BSTreeNode*&q; while(p!=NULL) { q=p; p=p->GetLeftChild(); } */ while (p->leftChild!=NULL) p=p->leftChild; return p; }

一般会同时初始化数组中的元素,如下所示:
一维数组语法
数据类型[] 数组名称=new 数据类型[大小]

对数组的赋值
声明时赋值
数据类型[] 数组名称=
声明后赋值
数据类型[] 数组名称=new 数据类型[大小]
数组名称[0]="四川"
foreach(类型 i in 对象/集合数组){

}

数组名.length;用于获取数组的元素个数
数组的角标以0开始

C# 复制代码
int[] array = new int[5];

数值数组元素的默认值为零,引用元素的默认值为 null,但您可以在创建数组的过程中初始化值,如下所示:

C# 复制代码
int[] array1 = new int[] ;

或者甚至这样来初始化:

C# 复制代码
int[] array2 = ;

数组的索引从零开始,因此数组中的第一个元素为元素 0。

C# 复制代码
string[] days = ;
System.Console.WriteLine(days[0]); // Outputs "Sun"
多维数组
从概念上来说,两维数组类似于网格,三维数组则类似于立方体。

C# 复制代码
// declare multidimension array (two dimensions)
int[,] array2D = new int[2,3];

// declare and initialize multidimension array
int[,] array2D2 = , };

// write elements in a multidimensional array
for (int i=0; i<2; i++)
{
for (int j=0; j<3; j++)
{
array2D[i,j] = (i + 1) * (j + 1);
}
}

// read elements in a multidimensional array
for (int i=0; i<2; i++)
{
for (int j=0; j<3; j++)
{
System.Console.Write(array2D[i,j]);
}
System.Console.WriteLine();
}
交错数组
多维数组的一种变体是交错数组,即由数组组成的数组。交错数组是一维数组,且每个元素自身是一个数组。作为元素的数组无需均为相同的大小。

声明交错数组的方式如下:

C# 复制代码
int[][] jaggedArray = new int[3][];

这样做会创建一个有 3 个数组的数组。这些数组可以按如下方式初始化:

C# 复制代码
jaggedArray[0] = new int[5];
jaggedArray[1] = new int[4];
jaggedArray[2] = new int[2];

For your question 小弟最近做课程设计 银行财务实时处理系统(二叉排序树的...,
给我留一个你的问题和Email,
如果你有更多的要求也可以告诉我们,
有时间可以帮你,
百度_Hi给我吧,
此回复对于所有需求和和来访者有效,
ES:\\1CD9EAE32E16F1EE403D49285A0D9348

扩展阅读:财务报表自动生成软件 ... 初级会计课程设计总结 ... 财务记账代办公司 ... 公司收支记账明细表 ... 免费财务记账软件 ... 小公司最简单财务流程 ... 培训机构的财务报表 ... 财务报表模板 全套 ... 财务记账软件排行榜前十名 ...

本站交流只代表网友个人观点,与本站立场无关
欢迎反馈与建议,请联系电邮
2024© 车视网