Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Database Programming

Authors: Chris Fehily

1st Edition

1937842312, 978-1937842314

More Books

Students also viewed these Databases questions