当前位置: 首页>>代码示例>>C++>>正文


C++ CreateTree函数代码示例

本文整理汇总了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 ;
}
开发者ID:psyclaudeZ,项目名称:Problems-of-Ural-and-UVa,代码行数:29,代码来源:UVa_548_Tree.cpp

示例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;

		}
	}
开发者ID:qs8607a,项目名称:Algorithm-22,代码行数:29,代码来源:Convert+Sorted+List+to+Binary+Search+Tree+.cpp

示例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);
 }
开发者ID:wuzongbin2008,项目名称:c_test,代码行数:31,代码来源:MAIN6-4.CPP

示例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);
    }
  }
}
开发者ID:EtlamGit,项目名称:minutor,代码行数:27,代码来源:properties.cpp

示例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_);
	}
}
开发者ID:SamJia,项目名称:Oj,代码行数:8,代码来源:BlockArt.cpp

示例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;
}
开发者ID:AnyaP,项目名称:Interview-preparation,代码行数:10,代码来源:task_3.cpp

示例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;
}
开发者ID:SuperMardle,项目名称:DataStructure,代码行数:13,代码来源:SearchTree.c

示例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);
    }
}
开发者ID:pathbox,项目名称:Study-Algorithm,代码行数:14,代码来源:Bitree_tree_main.c

示例9: CreateTree

void MyGameTreeCtrl::RefreshTree(string* pstrPanelName)
{
	m_mapNode.clear();
	CreateTree();
	m_bInsertData = true;
	EnsureVisible(GetRootItem());
}
开发者ID:2Dou,项目名称:PlayBox,代码行数:7,代码来源:MyGameTreeCtrl.cpp

示例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);	
	} 
 } 
开发者ID:silinlin8,项目名称:data-structure,代码行数:16,代码来源:BTree.cpp

示例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);
}
开发者ID:klhurley,项目名称:ElementalEngine2,代码行数:29,代码来源:COptionTreeWrapper.cpp

示例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);
}
开发者ID:Charlyhash,项目名称:DataStruct_C,代码行数:25,代码来源:huffman_c_imp.cpp

示例13: TreeTest

static void TreeTest (void)
{
	DirEntry_s *root;
	root = CreateTree(4, 9, 0);
	PrintTree(root, 0);
	DeleteTree(root);
}
开发者ID:taysom,项目名称:tau,代码行数:7,代码来源:dir.c

示例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;
}
开发者ID:mjyplusone,项目名称:CppPrimer,代码行数:16,代码来源:main.c

示例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();
	}
开发者ID:Edridan,项目名称:Black-Engine,代码行数:10,代码来源:CollisionSystem.cpp


注:本文中的CreateTree函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。