本文整理匯總了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();
}