コード例 #1
0
void Binary_search_tree::preorder_helper(BST_node* t) {
	if (t != nullptr) {
		std::cout << t->get_data() << " ";
		preorder_helper(t->get_left_child());
		preorder_helper(t->get_right_child());
	}
}
void preorder_helper(struct node *root, int *arr, int *i){
	if (root)
	{
		arr[*i] = root->data;
		(*i)++;
		preorder_helper(root->left, arr, i);
		preorder_helper(root->right, arr, i);
	}
}
void preorder_helper(struct node *root, int *arr,int *ind){
	
	if (root == NULL)
		return;

	arr[*ind] = root->data;
	*ind = *ind + 1;
	preorder_helper(root->left, arr,ind);
	preorder_helper(root->right, arr,ind);


	}
void preorder(struct node *root, int *arr)
{
	int i = 0;
	if (root && arr)
	{
		preorder_helper(root, arr, &i);
	}
}
void preorder(struct node *root, int *arr){
	

	if (arr == NULL)
		return;
	int ind = 0;

	preorder_helper(root, arr, &ind);

	}
コード例 #6
0
void Binary_search_tree::preorder() {
	preorder_helper(root);
	std::cout << "\n";
}