LinkedList Lab In this lab you will use singly linked list and swap Nodes. You will...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 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 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
Expert Answer:
Answer rating: 100% (QA)
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 the full answer
Related Book For
Integrated Accounting
ISBN: 978-1285462721
8th edition
Authors: Dale A. Klooster, Warren Allen, Glenn Owen
Posted Date:
Students also viewed these programming questions
-
developing the Singly-Linked LinkedList data structure, which will implement the provided List interface. In doing so, you will writea variety of methods from each. You will also be creating your own...
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
Q4. a- In a uniform electric field, what factors does the electrical potential energy depend on? b- What is the difference between APE electric and PE electric?
-
Due to rapid turnover in the accounting department, several transactions involving intangible assets were improperly recorded by Riley Co. in the year ended December 31, 2017: 1. Riley developed a...
-
The cost of taking your pet aboard the air flight with you in the continental United States varies according to the airlines. The prices for 14 of the major U.S. airlines in June 2009 were (in...
-
Select a publicly traded company or use a company assigned by your instructor. Using the firms most recent Form 10-K report (accessed through the SEC EDGAR database or from the companys website),...
-
FRED® (Federal Reserve Economic Data), a database of more than 3000 U.S. economic time series, contains historical data on foreign exchange rates. The following data show the foreign exchange...
-
Despite all the industrial progress and economic growth in Manchester (and other cities throughout Europe and the U.S.) the working class still suffered. They lived in cramped living quarters in...
-
Two particles, A and B, are in a uniform circular motion about a common center. The acceleration of particle A is 8.5 times that of particle B. The period of particle B is 2.0 times the period of...
-
What happens to a tax account when it is in "Currently Not Collectible" status?
-
Guy and Susan Johnson owns Johnsons Jewelry Products (JJP) stores in Florence, South Carolina. He believes that the stores have been successful and he wants to open a new store in Sumter about 30...
-
1. 2. 3. One of your portfolio managers, Rajesh Gupta, has recently complained that by measuring risk-adjusted returns using the Sharpe ratio, he is placed at an unfair disadvantage. He has stated...
-
The data show the number of points the winning team scored in a college football bowl game. Class Frequency 13-20 11 21-28 12 29-36 6 37-44 7 45-52 3 53-60 2 Download data Part 1 out of 2 Find the...
-
Describe two things that are important when understanding financial statements. What are some additional things to learn in reference to financial statements. How can you use financial statement...
-
Research Online for a local or surrounding area Agency/Organization that provides services for people seeking inpatient substance abuse treatment. Complete the following Agency Summary (formerly...
-
QUESTION 9 HC-O-C-R R-C-O-CH HC-O-P-O-CH-CH-NH3* O || O a. Phosphatidic acid, Serine O b. Lysophosphatidic acid, Serine, Free FA O c. Lysophosphatidylserine, Free FA O d. 2 Free FAs, Serine, Glycerol...
-
What account amount does the computer automatically calculate and display when a cash receipt transaction is entered?
-
Briefly describe the closing entries automatically generated by the computer.
-
The following problem provides practice of the applications described in this chapter. Step 1: Remove the Audit Test Questions 1-B at the end of this problem and fill in the answers as you work...
-
Summer and winter constellations are different because (a) of the spin of Earth about its polar axis. (b) the night sky faces in opposite directions in summer and winter. (c) of the tilt of Earths...
-
The longest-lived stars are those of (a) low mass. (b) high mass. (c) intermediate mass. (d) infinite mass.
-
What is the star nearest Earth? (a) Proxima Centauri (b) Polaris (c) Mercury (d) the Sun
Study smarter with the SolutionInn App