Question: LinkedList Lab In this lab you will use singly linked list and swap Nodes. You will first create a linked list with at least

LinkedList Lab In this lab you will use singly linked list and

LinkedList Lab In this lab you will use singly linked list and swap Nodes. You will first create a linked list with at least 8 Nodes in it. Then you ask user to get the position of the Node to swapped. If user enters n(some integer), then you will pick the node which is on nth from the beginning of the list and pick the nth from the end of the list. Then swap those two Nodes and print the updated Linked List. Here is an example: Let's say you created linked list: 10 -> 12 -> 31 -> 44-> 57 -> 62 -> 79->84 -> null 1 2 3 3 2 1 Let's say user input was n=3 You will read find the Node which is on the 3rd position from the beginning (In the above list Node on 3rd position from beginning is "31") You will read find the Node which is on the 3rd position from the end of the list (In the above list Node on 3rd position from end is "62") Means you will swap the Node containing date 31 and 62. After swap your resulting Linked List should be: 10 -> 12 -> 62 -> 44-> 57 -> 31 -> 79->84 -> null } Node.java public cl } int data; Node next; { Node (int data, Node next) { this.data data; this.next next; } public static void printList (Node head) { // write your logic to print linked list } public static Node swapNodes (Node head, int n) { // write you logic here // to swap the n'th node from the beginning with n'th node from the end } Demo.java public class Demo { public static void main(String [] args) { int[] arr= { 10, 12, 31, 44, 57, 62, 79, 84}; // create linked list from given array // print linked list. (call "printList" function) // get user input for "n" // swap nth Node (call "swapNodes" function) // print linked list (call "printList" function) } Submit your work in Canvas as ONE Zip file. Zip filename should be in format of FirstLast_Lab2.zip (ex. JohnDoe_Lab3.zip) Zip file should have following 4 files: (1) Node.java (2) Demo.java (3) Output.docx (screenshot sample input & output) (4) Pseudo-code.docx (write pseudo-code) 2 D

Step by Step Solution

3.39 Rating (146 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Here is an example Lets say you created linked list 1012314457627984 null 1 2 3 3 2 1 Lets say user input was n3 You will read find the Node which is ... View full answer

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!