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

I asked this question before but whoever answered did not used linked list, plea

ID: 3650571 • Letter: I

Question

I asked this question before but whoever answered did not used linked list, please if possible utilize LINKED LIST, please also post your output. thanks.


Write a function called "odd" that takes a linked list and returns the odd-numbered elements. Actually, write two functions called "odd" and "even". odd(L) returns a list of the 1st,3rd,5th... items in L. even(L) returns a list of the 2nd,4th,6th... items in L. And each function calls the other. These two functions are based on a simple observation. L.next is like L, but with the first item missing. If we take away the first item, item N+1 becomes item N. So the 2nd,3rd,4th elements of L are the 1st,2nd,3rd elements of L.next. Now if N+1 is odd, N is even, while if N+1 is even N is odd. So the odd members of L.next are even members of L, and the even members of L.next are odd members of L. Then we can compute odd(L) as follows. If L is null return null. Otherwise return a list whose first item is L.item, while its tail is even(L.next). To compute even(L): If L is null return null. Otherwise return odd(L.next). Your main function should read a list of positive integers from the command line, with -1 terminating the list. It should form a linked list containing these integers, compute the list of odd members, and print them.

Explanation / Answer

public class linkedlist
{
public static void main(String[] args)
{

List odd = new ArrayList();
List even = new ArrayList();
odd(L, odd, even);
}
void odd(L curNode, ArrayList oddList, ArrayList evenList)
{

if (curNode == null) return;


oddList.append(curNode.val);
even(curNode, oddList, evenList);
}

void even(L curNode, ArrayList oddList, ArrayList evenList)
{
if (curNode == null || curNode.next == null) return;


evenList.append(curNode.n ext.val);
odd(curNode.next.next, oddList, evenList);
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote