Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

add a construction to the node class in the program that is asses the initial va

ID: 3656915 • Letter: A

Question

add a construction to the node class in the program that is asses the initial values for the link x fields. simplify the addFirst method (this simplifiction is made possible by the use of the new construction). { public static void main(String[] args) { MyLinkedListL4 list = new MyLinkedListL4(); list.addFirst(1); list.addFirst(2); list.addFirst(3); System.out.println("Numbers on list"); list.traverse(); } } //============================================== class MyLinkedListL4 { private class Node { private Node link; private int x; } //---------------------------------- private Node first = null; //---------------------------------- public void addFirst(int d) { Node newNode = new Node(); newNode.x = d; newNode.link = first; first = newNode; } //---------------------------------- public void traverse() { Node p = first; while (p != null) { System.out.println(p.x); p = p.link; } } }

Explanation / Answer

# Assignment: number = 42 opposite = true # Conditions: number = -42 if opposite # Functions: square = (x) -> x * x # Arrays: list = [1, 2, 3, 4, 5] # Objects: math = root: Math.sqrt square: square cube: (x) -> x * square x # Splats: race = (winner, runners...) -> print winner, runners # Existence: alert "I knew it!" if elvis? # Array comprehensions: cubes = (math.cube num for num in list) var cubes, list, math, num, number, opposite, race, square, __slice = [].slice; number = 42; opposite = true; if (opposite) { number = -42; } square = function(x) { return x * x; }; list = [1, 2, 3, 4, 5]; math = { root: Math.sqrt, square: square, cube: function(x) { return x * square(x); } }; race = function() { var runners, winner; winner = arguments[0], runners = 2