Skip to content
Advertisement

Why this linked list rear operation snippet code throws error?

in the below snippet code contains 3 files, named main which is the main operation code, node file contains LinkedList creation and methods contains the linked list operation. In the add rear section throws error.. while execution. I have added the snippet error screshoot

Main.java

JavaScript

node.java

JavaScript

Methods.java

JavaScript

Execution Output Image

Advertisement

Answer

few mistakes here :

need to initialise ‘methods’ outside while loop. As at every input, it gets initialised.

JavaScript

Also in addrear(int data) method , need to handle head == null condition, i.e., how to add element when there are no elements in the list.

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement