Question: Please check the document to understand the context Oregon State University CS261 Data Structures Assignment 3 even(self) -> None: This method regroups list nodes by

Please check the document to understand the context

Oregon State University

CS261 Data Structures

Assignment 3

even(self) -> None:

This method regroups list nodes by first grouping all ODD nodes together followed by all

EVEN nodes (here, "odd" and "even" refer to the node position in the list (starting from 1),

not the node values). Please see the code examples below for additional details.

All work must be done "in place" without creating any new nodes. You are not allowed to

change the values of the nodes; the solution must change node pointers. Your solution must

have O(N) runtime complexity.

Solution Performance Checker: The allowance factor for this problem is 10.

Example #1:

test_cases = (

[1, 2, 3, 4, 5], list('ABCDE'),

[], [100], [100, 200], [100, 200, 300],

[100, 200, 300, 400],

[10, 'A', 20, 'B', 30, 'C', 40, 'D', 50, 'E']

)

for case in test_cases:

lst = CircularList(case)

print('INPUT :', lst)

lst.odd_even()

print('OUTPUT:', lst)

Output:

INPUT : CDLL [1 <-> 2 <-> 3 <-> 4 <-> 5]

OUTPUT: CDLL [1 <-> 3 <-> 5 <-> 2 <-> 4]

INPUT : CDLL [A <-> B <-> C <-> D <-> E]

OUTPUT: CDLL [A <-> C <-> E <-> B <-> D]

INPUT : CDLL []

OUTPUT: CDLL []

INPUT : CDLL [100]

OUTPUT: CDLL [100]

INPUT : CDLL [100 <-> 200]

OUTPUT: CDLL [100 <-> 200]

INPUT : CDLL [100 <-> 200 <-> 300]

OUTPUT: CDLL [100 <-> 300 <-> 200]

INPUT : CDLL [100 <-> 200 <-> 300 <-> 400]

OUTPUT: CDLL [100 <-> 300 <-> 200 <-> 400]

INPUT : CDLL [10 <-> A <-> 20 <-> B <-> 30 <-> C <-> 40 <-> D <-> 50 <-> E]

OUTPUT: CDLL [10 <-> 20 <-> 30 <-> 40 <-> 50 <-> A <-> B <-> C <-> D <-> E]

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 Programming Questions!