Beispiel #1
0
int main()
{
    printf("please in put the key\n");
    BST F;
    F=new node;
     F=CreatBST();
    Preorder(F);
     printf("which key do you want to search\n");
     keytype k;
     scanf("%d",&k);
     BST temp;
     temp=new node;
     temp=searchBST(k,F);
     if(temp)
     {
         printf("serach successfully\n");
     }
    printf("which key do you want to delete\n");
    scanf("%d",&k);
    int shorter;
    DeleteAVL(F,k,shorter);
    Preorder(F);


}
Beispiel #2
0
 bool Preorder(TreeNode *p_node, int cur_value)
 {
     if(p_node == NULL)
     {
         return false;
     }
     else if(p_node->left == NULL && p_node->right == NULL)//左右节点皆为NULL为叶子节点!
     {
         if(cur_value - p_node->val == 0)
         {
             return true;
         }
         else
         {
             return false;
         }
     }
     bool left = Preorder(p_node->left, cur_value - p_node->val);
     if(left)
     {
         return true;
     }
     bool right = Preorder(p_node->right, cur_value - p_node->val);
     return right; 
 }
Beispiel #3
0
void Preorder(node* root){
  if(root != NULL){
    cout << root->data << " ";
    Preorder(root->left);
    Preorder(root->right);
  }
}
Beispiel #4
0
void main()
{
	BinaryTree *tree = CreateBinaryTree();
	ElementTree item;

	item.data = 30;
	InsertTree(tree, item);
	item.data = 5;
	InsertTree(tree, item);
	item.data = 40;
	InsertTree(tree, item);
	item.data = 2;
	InsertTree(tree, item);
	item.data = 35;
	InsertTree(tree, item);
	item.data = 80;
	InsertTree(tree, item);

	Preorder(tree->root);
	printf("\n");
	item.data = 80;
	DeleteTreeNode(tree->root, item);

	Preorder(tree->root);

}
void Preorder(node *root) {
    if(root==NULL){
        return;
    }
    cout<<root->data<<" ";
    Preorder(root->left);
    Preorder(root->right);
}
Beispiel #6
0
void Preorder(BiTree T)
{ 
    if(T) { 
        printf("%c",T->data); 
        Preorder(T->lchild); 
        Preorder(T->rchild); 
    } 
}
void Preorder(BSTNode * current)
{
    if(current!=NULL){
        std::cout << current->id << " " ;
        Preorder(current->left);
        Preorder(current->right);
    }
}
Beispiel #8
0
//Program to display the tree in preorder
void Preorder(NODE R)
{
	if(R==NULL)
		return;
	printf(" %d\t",R->key);
	Preorder(R->llink);
	Preorder(R->rlink);
}
void Preorder(Node* node){
	if(node == NULL){
		return;
	}
	printf("%d\n", node -> data);
	Preorder(node -> left);
	Preorder(node -> right);
}
Beispiel #10
0
void Preorder(btNode* pRoot)
{
	if(pRoot == NULL)
		return;
	cout<<pRoot->data<<"\t";
	Preorder(pRoot->left);
	Preorder(pRoot->right);
}
 void Preorder(TreeNode* root, vector<int>& ret)
 {
     if(root == NULL)
       return;
     Preorder(root->left, ret);
     ret.push_back(root->val);
     Preorder(root->right, ret);
 }
Beispiel #12
0
void Preorder(Btree BT)
{
    if(!isEmpty(BT))
    {
        printf("%c",BT->data);
        Preorder(BT->lchild);
        Preorder(BT->rchild);
    }
}
//先序遍历(递归)
void Preorder(BiNode T)
{
    if(T)
    {
        printf("%c ",T->data);
        Preorder(T->lch); //遍历左子树
        Preorder(T->rch); //遍历右子树
    }
}
Beispiel #14
0
void Preorder(BST BT)
{
    if(!isEmpty(BT))
    {
        printf("%d ",BT->data.key);
        Preorder(BT->lchild);
        Preorder(BT->rchild);
    }
}
Beispiel #15
0
void BinaryTree::Preorder(Node* temp)
{
    if (temp != NULL)
    {
        std::cout << temp->data<<" ";
        Preorder(temp->left);
        Preorder(temp->right);
    }
}
Beispiel #16
0
//先序遍历 (递归)
void Preorder (struct BiNode *T)
{                    
   if(T){
      printf("%c",T->data);             // 访问根结点
       
      Preorder(T->lch); // 遍历左子树
      Preorder(T->rch);// 遍历右子树
   }
}
Beispiel #17
0
void Preorder(AVLTree tree)
{
    if(tree != NULL)
    {
        printf("%d ", tree->value);
        Preorder(tree->left);
        Preorder(tree->right);
    }
}
Beispiel #18
0
void Preorder(Node * arr, int ind)
{
	printf("%d ", ind);

	if ((&arr[ind]) -> lc != -1)
		Preorder(arr, (&arr[ind]) -> lc);
	if ((&arr[ind]) -> rc != -1)
		Preorder(arr, (&arr[ind]) -> rc);
}
Beispiel #19
0
/* Visita em Preorder */
   void Preorder(arv_bin * root )
   {
      if (root)
      {
         printf("\n Pre-Ordem::%s\t||\t %d" ,root->info, root->ordem);
         printf("\n Filhos  Esq: %s\t|| Dir: %s " ,root->left->info, root->right->info);
         Preorder( root->left );
         Preorder( root->right );
      }
   }
Beispiel #20
0
	void Preorder(tree *root)
	{
		
		if(root)
		{
		printf("  %d  ",root->data);
		Preorder(root->left);
		Preorder(root->right);
		}
	return;
	}
Beispiel #21
0
void Preorder(Node * h)
{
	if (h == NULL)
		return;
	if (h -> cut == 'V' || h -> cut == 'H')
		printf("%c", h -> cut);
	else
		printf("(%le,%le)", h -> width, h-> height);
	Preorder(h -> lc);
	Preorder(h -> rc);
}
void Preorder(int *arr, int index)
{
  // if root node is empty;
  if(arr[index] == -1) {
    // Then do nothing;
    return ;
  }
  // print the root node of tree;
  printf("%d ", arr[index]);
  // recursive function to the left branch in tree;
  Preorder(arr, index*2 + 1);
  // recursive function to the right branch in tree;
  Preorder(arr, index*2 + 2);
}
void Preorder(nodeT *p, int level)
{


	int i;
	if (p != NULL)
	{
		for (i = 0; i <= level; i++)
			printf(" "); /* for nice listing */
		printf("%d\n", p->data);
		Preorder(p->left, level + 1);
		Preorder(p->right, level + 1);
	}

}
Beispiel #24
0
int main()
{
        treeNode *root = NULL;
        root = Insert(root, 5);
        root = Insert(root, -1);
        root = Insert(root, 3);
        root = Insert(root, -14);
        root = Insert(root, 8);
        root = Insert(root, 10);
        root = Insert(root, 9);
        root = Insert(root, 6);

        printf("\nBefore Deletion BST in Inorder traversal\n ");
        Inorder(root);
        printf("\n\n");
        root = Delete(root,5);
        root = Delete(root,-1);

        printf("After Deletion BST\n");
        printf("\nInorder traversal\n");
        Inorder(root);
        printf("\nPreorder traversal\n");
        Preorder(root);
        printf("\nPostorder traversal\n");
        Postorder(root);

}
Beispiel #25
0
int main()
{
    //建树 
    struct BiNode *T,*root;
    T = root;
    printf("The fuction Create() is called.\n");
    Create(T);
     
    //三种遍历递归算法 
    printf("\n");    
    printf("The fuction Preorder() is called.\n");
    Preorder(root);
     
    printf("\n");
    printf("The fuction Inorder() is called.\n");
    Inorder(root);
     
    printf("\n");
    printf("The fuction Postorder() is called.\n");
    Postorder(root);
     
     
    printf("\n");

    return 0;
}
 vector<int> inorderTraversal(TreeNode *root) {
     // Start typing your C/C++ solution below
     // DO NOT write int main() function
     vector<int> ret;
     Preorder(root, ret);
     return ret;
 }
Beispiel #27
0
void Display(AVLTree root)
{
    printf("\n前序遍历: ");
    Preorder(root);
    printf("\n中序遍历: ");
    Inorder(root);
    printf("\n后序遍历: ");
    Postorder(root);
    printf("\n");
}
// print the tree in preorder, inorder, and postorder form;
void print_tree(int *arr)
{
  printf("Preorder: ");
  Preorder(arr, 0);
  puts("");
  printf("Inorder: ");
  Inorder(arr, 0);
  puts("");
  printf("Postorder: ");
  Postorder(arr, 0);
  puts("");
}
Beispiel #29
0
void Display(AVLTree root)
{
    printf("\n== 前序遍历: ");
    Preorder(root);
    printf("\n== 中序遍历: ");
    Inorder(root);
    printf("\n== 后序遍历: ");
    Postorder(root);
    printf("\n");
    printf("== 高度: %d\n", AVLHeight(root));
    printf("== 最小值: %d\n", AVLMin(root)->value);
    printf("== 最大值: %d\n", AVLMax(root)->value);
}
Beispiel #30
0
int  main()
{
    char a;
    Btree BT,head;
    head=BT;
    BT=CreatBtree();
    Preorder(BT);
    printf("\n");


   /* constPost(BT);
     printf("\n");
     Post(BT);
      printf("\n");

     printf("dsf");
    Preorder(head);*/
      getchar();
      scanf("%c",&a);
      Delete(a,BT);
      Preorder(BT);
    return 0;
}