<prompt> Kutokana na mizizi ya mti binary, kurudi preorder traversal ya maadili node yake.Andika kazi ya Java ambayo hufanya yafuatayo.  <response>: Heres a Java function that performs the desired task:public static List preorderTraversalTreeNode root List result new ArrayList; Stack stack new Stack; if root null return result; stack.pushroot; while!stack.isEmpty TreeNode current stack.pop; result.addcurrent.val; if current.right ! null stack.pushcurrent.right; if current.left ! null stack.pushcurrent.left; return result;This function uses a stack to keep track of nodes while traversing the tree. It starts by pushing the root node onto the stack. It then enters a loop where it pops the top node from the stack, adds its value to the result list, and then pushes its right and left children if they exist onto the stack. This continues until the stack is empty and all nodes have been traversed. 