Given a Binary Search Tree, create a function (using C++ or…

Given a Binary Search Tree, create a function (using C++ or pseudocode) that takes in the root of the BST and returns a sorted array of all the nodes in linear time. You can assume the tree is pre-built and no need to create your own insertion function. The TreeNode class has been defined for you: class TreeNode { public: int val; TreeNode *left; TreeNode *right; };