PLEASE ANSWER ASAP
Consider the implementation of method swap().
In Lab 8, consider the implementation of method swap(). First, consider the corner case where the nodes to be swapped are adjacent as shown below. Assume that both nodes I and J to be swapped exist in the linked list. To perform swapping correctly, we have to find the following nodes first in another methods. • A: the node before I. If I is the list head, then A=null; • B: the ode after I. In this corner case, B== J. • X: the node before J. In this corner case, X==I. • Y: the node after J. If J is the list tail, then Y==null; Below is the graph that illustrates how to implement this method. head tail head tail 1 5 7 7 А B A 1 B Y J Z Y i) Z Give the codes according to the above illustration. Fill in the missing pieces. . • If (head==1) head. =___a___; If (J.next==null) tail b ; • If (A!=null) A.next C___; • J.next d ; • I.next e___; =
Hints: • Check method swap in the lab partial answer keys here: answer.LinkedList.java • Follow the instructions at the top of the program file. • Plug in your answers and see if the program output is the same as the expected. a ✓ [Choose ] J z I None is a correct answer b c [ Choose ] d [Choose ] A e ► [Choose ]
PLEASE ANSWER ASAP Consider the implementation of method swap().
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am