• 大小: 11.11MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-07-01
  • 语言: Html/CSS
  • 标签: 多叉树  

资源简介

说明地址 http://www.cnblogs.com/l2017/p/8660089.html

资源截图

代码片段和文件信息

#include“display_Multiway-Trees.h“
#include 
#include
#include
#include
#include

using namespace std;
static int sum;
int Multiway_tree::n = 0;
bool Multiway_tree::MakeTree(Multiway_tree* &T int s1 int s2 int len string **&preorder string *&inorder)
{
if (len <= 0)
{
T = NULL;
return 1;
}
else
{
T = new Multiway_tree(preorder[s1][0] preorder[s1][1]);
int i;
for (i = 0; i MakeTree(T->child s1 + 1 s2 i preorder inorder);
MakeTree(T->brother s1 + i + 1 s2 + i + 1 len - (i + 1) preorder inorder);
}
return 1;
}


void Multiway_tree::MakeRelation(Multiway_tree *root)
{
if (root == NULL)return;
if (root->child != NULL)root->child->parent = root;
if (root->brother != NULL)root->brother->parent = root->parent;
MakeRelation(root->child);
MakeRelation(root->brother);
}
bool  Multiway_tree::readfile(Multiway_tree *&root)
{
fstream inorderStream;
fstream preorderStream;
preorderStream.open(“preorder.txt“ ios::in);
string **preorder;
preorderStream >> sum;
preorder = new string*[sum];
for (int i = 0; i < sum; i++)
preorder[i] = new string[2];
int i = 0;
char temp = ‘0‘;
string mateTemp[13];
while (!preorderStream.eof())
{
preorderStream >> preorder[i][0]>> preorder[i][1];
++i;
}
preorderStream.close();
inorderStream.open(“inorder.txt“ ios::in);
string *inorder = new string[sum];
i = 0;
while (!inorderStream.eof())
{
inorderStream >> inorder[i];
++i;
}
inorderStream.close();
MakeTree(root 0 0sum preorder inorder);
MakeRelation(root);
delete[] preorder;
delete[] inorder;
return 1;
}

void Multiway_tree::preOrder(const Multiway_tree* root fstream &f1)
{
if (root == NULL) { return; }

f1 << root->name;
 f1 << ‘\n‘;
preOrder(root->child f1);
preOrder(root->brother f1);
}
void Multiway_tree::inOrder(const Multiway_tree* root fstream &f2)
{
if (root == NULL) { return; }
inOrder(root->child f2);
f2 << root->name << ‘\n‘;
inOrder(root->brother f2);
}

bool Multiway_tree::writefile(const Multiway_tree *root)
{
fstream f1 f2;
f1.open(“preorder.txt“ ios::out);
f2.open(“inorder.txt“ ios::out);

preOrder(root f1);
inOrder(root f2);
f1.close();
f2.close();
cout << “keep sussced“ << endl;
return 1;
}

void positionadd(Multiway_tree*root int n)
{
if (!root)return;
Multiway_tree*pcur = root;
stacks;
while (pcur || !s.empty())
{
if (pcur)
{
if (pcur == root->brother)break;
pcur->positon += n;
s.push(pcur);
pcur = pcur->child;
}
else
{
pcur = s.top();
s.pop();
pcur = pcur->brother;
}
}
}
void Multiway_tree::display(Multiway_tree *root const int distance)
{

if (root == NULL)
return;

root->positon = 0;
root->positionmark = “ “;
int *namenum = new int[sum];
stack

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-04-09 17:58  display_multiway-trees\
     目录           0  2018-04-09 17:55  display_multiway-trees\.vs\
     目录           0  2018-04-09 17:55  display_multiway-trees\.vs\display_multiway-trees\
     目录           0  2018-04-09 17:55  display_multiway-trees\.vs\display_multiway-trees\v14\
     文件       23552  2018-04-09 17:58  display_multiway-trees\.vs\display_multiway-trees\v14\.suo
     目录           0  2018-04-09 17:56  display_multiway-trees\Debug\
     文件      146944  2018-04-09 17:56  display_multiway-trees\Debug\display_multiway-trees.exe
     文件      676996  2018-04-09 17:56  display_multiway-trees\Debug\display_multiway-trees.ilk
     文件     1273856  2018-04-09 17:56  display_multiway-trees\Debug\display_multiway-trees.pdb
     目录           0  2018-04-09 17:55  display_multiway-trees\display_multiway-trees\
     文件        1348  2018-04-09 17:55  display_multiway-trees\display_multiway-trees.sln
     文件    29261824  2018-04-09 17:58  display_multiway-trees\display_multiway-trees.VC.db
     目录           0  2018-04-09 17:56  display_multiway-trees\display_multiway-trees\Debug\
     目录           0  2018-04-09 17:56  display_multiway-trees\display_multiway-trees\Debug\display_.0D647383.tlog\
     文件        1610  2018-04-09 17:56  display_multiway-trees\display_multiway-trees\Debug\display_.0D647383.tlog\CL.command.1.tlog
     文件       37428  2018-04-09 17:56  display_multiway-trees\display_multiway-trees\Debug\display_.0D647383.tlog\CL.read.1.tlog
     文件        1974  2018-04-09 17:56  display_multiway-trees\display_multiway-trees\Debug\display_.0D647383.tlog\CL.write.1.tlog
     文件         222  2018-04-09 17:56  display_multiway-trees\display_multiway-trees\Debug\display_.0D647383.tlog\display_multiway-trees.lastbuildstate
     文件        1718  2018-04-09 17:56  display_multiway-trees\display_multiway-trees\Debug\display_.0D647383.tlog\link.command.1.tlog
     文件        3310  2018-04-09 17:56  display_multiway-trees\display_multiway-trees\Debug\display_.0D647383.tlog\link.read.1.tlog
     文件         958  2018-04-09 17:56  display_multiway-trees\display_multiway-trees\Debug\display_.0D647383.tlog\link.write.1.tlog
     文件         520  2018-04-09 17:56  display_multiway-trees\display_multiway-trees\Debug\display_multiway-trees.log
     文件      474730  2018-04-09 17:56  display_multiway-trees\display_multiway-trees\Debug\display_Multiway-Trees.obj
     文件       31246  2018-04-09 17:56  display_multiway-trees\display_multiway-trees\Debug\main.obj
     文件      896000  2018-04-09 17:56  display_multiway-trees\display_multiway-trees\Debug\vc140.idb
     文件      544768  2018-04-09 17:56  display_multiway-trees\display_multiway-trees\Debug\vc140.pdb
     文件        8633  2018-04-08 23:14  display_multiway-trees\display_multiway-trees\display_Multiway-Trees.cpp
     文件         925  2018-04-08 23:14  display_multiway-trees\display_multiway-trees\display_Multiway-Trees.h
     文件        7532  2018-04-09 17:56  display_multiway-trees\display_multiway-trees\display_multiway-trees.vcxproj
     文件        1186  2018-04-09 17:56  display_multiway-trees\display_multiway-trees\display_multiway-trees.vcxproj.filters
     文件          64  2018-04-08 23:22  display_multiway-trees\display_multiway-trees\inorder.txt
............此处省略2个文件信息

评论

共有 条评论

相关资源