Answer to Question #300231 in Java | JSP | JSF for Akash srivastava

Question #300231

You are given a Singly linked list and an integer K. Your task is to insert the integer K at the head of the given linked list

Input

User Task:

Since this will be a functional problem, you don't have to take input. You just have to complete the function addElement() that takes head node and the element K as a parameter.



Constraints:

1 <=N<= 1000

1 <=K, value<= 1000

Output

Return the head of the modified linked list


1
Expert's answer
2022-02-20T10:00:00-0500
public class Main {
    public static Node addElement(Node head, int k) {
        Node node = new Node(k);
        node.next = head;
        return node;
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS