Answered step by step
Verified Expert Solution
Question
1 Approved Answer
concatenate Implement a method which takes two LinkedIntLists as input and returns a new list containing all the items of the first followed by all
concatenate
Implement a method which takes two LinkedIntLists as input and returns a new list containing all the items of the first followed by all the items of the second. Don't modify the input lists; use the new keyword to create new objects instead. Your implementation should run in linear time i.e. without the use of nested for-loops.
list1: front ? 1 ? 2 ? 3 ? /list2: front ? 4 ? 5 ? 6 ? /
If you made the call concatenate(list1, list2), then it should return a new list:
return: front ? 1 ? 2 ? 3 ? 4 ? 5 ? 6 ? /
and list1 and list2 would remain unchanged:
list1: front ? 1 ? 2 ? 3 ? /list2: front ? 4 ? 5 ? 6 ? /
edintListProblemsTests IntTreeProblems.java X IntTreeProblemsTests.java X MapProblemsTests.java X LinkedIn /** * Returns a list consisting of the integers of a followed by the integers * of n. Does not modify items of A or B. */ 4 usages _ mxo* public static LinkedIntList concatenate (LinkedIntList a, LinkedIntList b) { // Hint: you'll need to use the 'new' keyword to construct new objects. LinkedIntList combo = new LinkedIntList(a. front. data) ; ListNode temp = combo . front; ListNode beginning = a. front; if (a. front == null) { return b; if (b. front == null) { { return a; while (beginning != null) { LinkedIntList tempList = new LinkedIntList (beginning. data); temp. next = tempList. front; beginning = beginning. next; temp = temp. next; temp. next = b. front; return combo; emsTests x O Tests failed: 3, passed: 7 of 10 tests - 29ms java . lang. NullPointerException: Cannot read field "data" because "a. front" is nutE * REMEMBER THE FOLLOWING RESTRICTIONS: - do not call any methods on the 'LinkedIntList' objects. - do not construct new 'ListNode' objects for 'reverses' or 'firstToLast' (though you may have as many 'ListNode' variables as you like). do not construct any external data structures such as arrays, queues, lists, etc. do not mutate the 'data' field of any node; instead, change the list only by modifying links between nodes Step 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