Question: Linked List must be returned with even nodes first, then odd. As shown in the examples. Problem 3: GroupLinkedList class (25') Description: Given a singly

Linked List must be returned with even nodes first, then odd. As shown in the examples.

Linked List must be returned with even nodes first, then odd. As

Problem 3: GroupLinkedList class (25') Description: Given a singly linked list, group all even nodes (not the value of node, but the node number) together followed by all the odd nodes. Example1: Input: a>b>a>b>a>b>a> null Output: b->b->b->a->a->a->a->null Explanation: the first b is the 2nd node (an even); the first a is the 1st node (an odd). Example2: Input: a ->null Output: a->null You should do it in-place, namely, you will NOT create another linked lists or arrays, and then add the nodes back to form the new linked list. Hints: 1) Please introduce two moving pointers, and interleave all those even and odd nodes. You can also introduce some helper pointers to keep the original value of the links. 2) The result of the first step will give your two linked list, for example: a list of all even nodes: b>b>b> null, and a list of all odd nodes: a->a->a->a->null; 3) You then need to link these two lists together, resulting in: b->b->b->a->a->a->a->null Outputs: Your outputs should look something as follows. \$ java GroupLinkedList List (firstlast): {a}{b}{a}{b}{a}{b}{a} List (first->last): {b}{b}{b}{a}{a}{a}{a}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!