Given a binary tree, write a method to recursively traverse the tree in the preorder manner. Mark a node as visited by adding its

`data`

to the list - `Arraylist <Integer> preorderedList`

.
Example: 1 / \ 2 3 ==> 1245367 / \ / \ 4 5 6 7

Need a **hand?** Try out these hints, one at a time.

Pre-order traversal

1. Add the

2. Traverse the

3. Traverse the

1. Add the

`data`

of the current node to the Arraylist. 2. Traverse the

`left`

subtree by recursively calling the `preorder`

method. 3. Traverse the

`right`

subtree by recursively calling the `preorder`

method.
Use

`add`

to add the node's data to the `ArrayList<Integer>`

.
//Populated the elements of the tree in the below list in preorder format ArrayList<Integer> preorderedList = new ArrayList<Integer>(); public void preorder(TreeNode root) { }

**C**

**Java**

**Python**