class which contains a node class. The node class will house the data (integer in this case) and a pointer to the next node element. Populate your linked list with the following integers and print it . 50, 11, 33, 21, 40, 71 No you do not need to p
java
Please provide Comment and test cases
Create a Linked List data structure by writing your own Linked List
class which contains a node class. The
node class will house the data (integer in this case) and a pointer to the next
node element. Populate your linked list with the following integers and print it .
50, 11, 33, 21, 40, 71
No you do not need to print the commas ;)
Delete N-th node from the end of the linked list and print the linked list after deletion. Here N = 2
Below is the expected output after deleting the second last element.
50, 11, 33, 21, 71
ATTN : Note : Here we do not know the length of the list.
Complete the above deletion operation without calculating the length of the list.
Your solution should only make a single pass through the linked list, adhering
to O(n) time complexity overall and O(1) space complexity.
Hint : Maintain two pointers : a ’Fast’ Pointer and a ’Slow’ pointer. Initialize both pointers to a dummy node which points to the head of the list.
Then starting a counter from zero, move the ’fast’ pointer two places forward,
to maintain a gap of two between the fast and slow pointers and then move
both in tandem. Finally, when the fast pointer reaches the end of the list , the
slow pointer will be at the third last node. You can now delete the second last
node.
![Link List
• Create a function example, push(int data) to populate the linked list by the input
from the user
• Take the value of “N" as input from the user
o Delete the Nth node from the end (tail) of the Linked List
Test Cases
Test case 1:
o Only one value in the Linked List => N=1: Return "Null" as string.
o Check for "Invalid Input" (e.g. non integer input)
• Test case 2:
o Linked List = null that means; head==null; for any value of N; return "Invalid input" or "Null"
(some error message)
• Test case 3:
o lf N> Length of the Linked List; Prompt the user that N is greater than the length of the list (e.g.
N>input size, think of going back than the head of list)](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F7d009b7a-5e1c-499c-a434-821054b9abc8%2F72d5dfe0-eb55-48f7-9275-4dbe00f46b6f%2Fr72gfsk_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 2 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)