Examveda

Select the code snippet which performs pre-order traversal.

A.

public void preorder(Tree root)
{
	System.out.println(root.data);
	preorder(root.left);
	preorder(root.right);
}

B.

public void preorder(Tree root)
{
	preorder(root.left);
	System.out.println(root.data);
	preorder(root.right);
}

C.

public void preorder(Tree root)
{
	System.out.println(root.data);
	preorder(root.right);
	preorder(root.left);
}

D.

public void preorder(Tree root)
{
	preorder(root.right);
	preorder(root.left);
        System.out.println(root.data); 
}

Answer: Option A


This Question Belongs to Data Structure >> Binary Search Trees(B Tree)

Join The Discussion

Related Questions on Binary Search Trees(B Tree)