Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I need help on #10. 1. Create a Node class that has a string called data and a pointer to the next Node called next.
I need help on #10.
1. Create a Node class that has a string called data and a pointer to the next Node called next. Note: Because we want Nodes to be useful for many things, we'll use Strings and use int/ double parsing where necessary. This is inefficient both due to the extra processing of parsing and the much higher memory usage of Strings compared to ints and doubles. public class Node{ public String data; public Node next; } 2. Create a function node ToString() that takes a head Node (which may be null). The returned String should look something like this: [A, =>] [B, =>] [C, null] public static String nodeToString (Node h) public static String nodeToString(Node h){ if(h == null){ return "null"; } String rv = ""; while(h != null){ if(h.next != null) rv += "[" + h.data + ", =>]"; else ry += "[" + h.data + ", null]"; h = h.next; } return rv; } 3. Create a function get() that takes a head Node and an int index. get() should return the String in the nth Node. Start indexing at 0. If the index is out of bounds, return null. public static String get (Node h, int index) public static String get(Node h, int index) { String ans = ""; Node c = h; for(int i = 0; c != null && iStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started