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

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

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)
Transcribed Image Text: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)
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY