本文整理汇总了C++中CreateTree函数的典型用法代码示例。如果您正苦于以下问题:C++ CreateTree函数的具体用法?C++ CreateTree怎么用?C++ CreateTree使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CreateTree函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateTree
void CreateTree( int lo, int hi, int root, bool left ) {
int pivotIndex, tmpIndex;
//printf( "l:%d h:%d\n", lo, hi);
if ( lo >= hi )
return ;
for ( int i = lo; i < hi; ++i ) {
if ( inOrder[i] == postOrder[pivotCnt] ) {
pivotIndex = i;
--pivotCnt;
break;
}
}
tmpIndex = ++fuck;
tree[tmpIndex].val = inOrder[pivotIndex];
tree[tmpIndex].parentIndex = root;
if ( left )
tree[root].lChildIndex = tmpIndex;
else
tree[root].rChildIndex = tmpIndex;
CreateTree( pivotIndex + 1, hi, tmpIndex, true );
CreateTree( lo, pivotIndex, tmpIndex, false );
return ;
}
示例2: CreateTree
TreeNode * CreateTree(ListNode* node,int len)
{
if( len == 1)
{
TreeNode * t = new TreeNode(node->val);
t->right = t->left = NULL;
allNodes.push_back(t);
return t;
}
else
{
ListNode * cur= node;
int i = 1;
do
{
node = node->next;
}while(++i <= len/2);
TreeNode * t = new TreeNode(node->val);
t->left = CreateTree(cur,len/2);
if(len-len/2-1== 0)
t->right = NULL;
else
t->right = CreateTree(node->next,len-len/2-1);
allNodes.push_back(t);
return t;
}
}
示例3: main
void main()
{
int i;
PTree T,p;
TElemType e,e1;
InitTree(T);
printf("构造空树后,树空否? %d(1:是 0:否) 树根为%c 树的深度为%d\n",TreeEmpty(T),Root(T),TreeDepth(T));
CreateTree(T);
printf("构造树T后,树空否? %d(1:是 0:否) 树根为%c 树的深度为%d\n",TreeEmpty(T),Root(T),TreeDepth(T));
printf("层序遍历树T:\n");
TraverseTree(T,vi);
printf("请输入待修改的结点的值 新值: ");
scanf("%c%*c%c%*c",&e,&e1);
Assign(T,e,e1);
printf("层序遍历修改后的树T:\n");
TraverseTree(T,vi);
printf("%c的双亲是%c,长子是%c,下一个兄弟是%c\n",e1,Parent(T,e1),LeftChild(T,e1),RightSibling(T,e1));
printf("建立树p:\n");
InitTree(p);
CreateTree(p);
printf("层序遍历树p:\n");
TraverseTree(p,vi);
printf("将树p插到树T中,请输入T中p的双亲结点 子树序号: ");
scanf("%c%d%*c",&e,&i);
InsertChild(T,e,i,p);
Print(T);
printf("删除树T中结点e的第i棵子树,请输入e i: ");
scanf("%c%d",&e,&i);
DeleteChild(T,e,i);
Print(T);
}
示例4: if
void Properties::ParseList(QTreeWidgetItem* node, const IterableT& seq) {
typename IterableT::const_iterator it, itEnd = seq.end();
int i = 0;
// skip 1 sized arrays
if (seq.size() == 0) {
// empty
if (node)
node->setData(1, Qt::DisplayRole, "<empty>");
} else if (seq.size() == 1) {
CreateTree(node, seq.first());
if (node)
node->setData(1, Qt::DisplayRole, GetSummary("[0]", seq.first()));
} else {
for (it = seq.begin(); it != itEnd; ++it) {
QTreeWidgetItem* child = new QTreeWidgetItem();
QString key = QString("[%1]").arg(i++);
child->setData(0, Qt::DisplayRole, key);
child->setData(1, Qt::DisplayRole, GetSummary(key, *it));
CreateTree(child, *it);
if (node)
node->addChild(child);
else
ui->propertyView->addTopLevelItem(child);
}
}
}
示例5: CreateTree
void CreateTree(Node *p) {
if (p->low_ < p->high_) {
p->left_ = new Node(p->low_, (p->low_ + p->high_) / 2);
CreateTree(p->left_);
p->right_ = new Node((p->low_ + p->high_) / 2 + 1, p->high_);
CreateTree(p->right_);
}
}
示例6: CreateTree
Node* CreateTree(It begin, It end) {
if (end - begin == 0) {
return nullptr;
}
Iterator middle = begin + (end - begin) / 2; // Should I be afraid of (from < to)?
Node* root = new Node(*middle);
root->left = CreateTree(begin, middle);
root->right = CreateTree(middle + 1, end);
return root;
}
示例7: CreateTree
SearchTree CreateTree(SearchTree T) {
int temp;
scanf("%d", &temp);
if(temp == -1)
T = NULL;
else {
T = (SearchTree)malloc(sizeof(TreeNode));
T->data = temp;
T->left = CreateTree(T->left);
T->right = CreateTree(T->right);
}
return T;
}
示例8: CreateTree
//先序拓展建立二叉树
void CreateTree(BiTree &T)
{
T = (BiNode*) malloc (sizeof(BiNode));
printf("Enter the data \n");
scanf("%c ",&T->data);
if(T->data == '#') T == NULL;
if(T)
{
printf("");
CreateTree(T->lch);
CreateTree(T->rch);
}
}
示例9: CreateTree
void MyGameTreeCtrl::RefreshTree(string* pstrPanelName)
{
m_mapNode.clear();
CreateTree();
m_bInsertData = true;
EnsureVisible(GetRootItem());
}
示例10: CreateTree
CreateTree(BTree &T) //必须声明为指针的指针(BTree *T)或者指针的引用 (BTree &T) 因为有 NULL指针;
{
char c;
scanf("%c",&c);
if(c ==' ')
{
T = NULL;
}
else
{
T = (BTree)malloc(sizeof(BNode));
(T)->data = c;
CreateTree((T)->lchild);
CreateTree((T)->rchild);
}
}
示例11: COptionTree
void COptionTreeWrapper::Serialize(CHashString objName, vector<CHashString> objTypes, IArchive &ar, bool bRead)
{
if (m_mTrees[objName.GetUniqueID()].m_Tree == NULL)
{
m_mTrees[objName.GetUniqueID()].m_Tree = new COptionTree();
m_mTrees[objName.GetUniqueID()].m_Tree->Create(m_Style, m_Rect, m_pParentWnd, m_TreeOptions, m_ID);
m_mTrees[objName.GetUniqueID()].m_Root = m_mTrees[objName.GetUniqueID()].m_Tree->InsertItem(new COptionTreeItem());
CString label;
label = objName.GetString();
label += _T("(");
label += objTypes[0].GetString();
label += _T(")");
m_mTrees[objName.GetUniqueID()].m_Root->SetLabelText(label);
for (UINT i=0; i<objTypes.size(); i++)
{
CreateTree(objTypes[i].GetString(), objName);
}
m_vRootNames.push_back(objName);
}
if (bRead)
{
SerializeIn(ar, objName);
}
else
{
SerializeOut(ar, objName);
}
ExpandOneRoot(objName);
}
示例12: TEST_HUFMAN
void TEST_HUFMAN()
{
freopen("input.txt", "r", stdin);
int n; //需要编码的字符的个数
scanf("%d", &n);
int i;
int *wet = (int *)malloc(n * sizeof(int)); //存放每个字符的权值
for (i = 0; i<n; i++)
{
scanf("%d", wet + i);
}
HUffmanCode HC; //保存赫夫曼编码
HuffmanTree HT = CreateTree(wet, n); //生成赫夫曼树
HufmanCoding(HT, HC, n); //求每个字符的赫夫曼编码
printf("哈夫曼编码如下:\n");
for (i = 0; i<n; i++)
{
puts(HC[i]);
}
free(wet);
}
示例13: TreeTest
static void TreeTest (void)
{
DirEntry_s *root;
root = CreateTree(4, 9, 0);
PrintTree(root, 0);
DeleteTree(root);
}
示例14: CreateTree
BiTree CreateTree()
{
BiTree T;
char ch;
scanf("%c",&ch);
if(ch=='#') T=NULL;
else
{
T=(BiTree)malloc(sizeof(BiTNode));
if(!T) exit(0);
T->data=ch;
T->lchild=CreateTree();
T->rchild=CreateTree();
}
return T;
}
示例15: m_CurrentDeep
/*
* Collision Tree
*/
CollisionTree::CollisionTree(const sf::FloatRect & i_SubRect, const ubyte i_MaxObjects, const ubyte i_TreeDeep)
:m_TreeDeep(i_TreeDeep), m_CurrentDeep(1), m_NodeBox(i_SubRect), m_NodeCapacity(i_MaxObjects), m_IsLeaf(true)
{
m_SubNodes[0] = m_SubNodes[1] = m_SubNodes[2] = m_SubNodes[3] = nullptr;
// Create the tree
CreateTree();
}