Given a stack myData: Tom, Sam (top is Tom), and the followi…