Question
Which of the following code snippets correctly
implements a singly linked list in Java, including the ability to insert a new node at the beginning? class Node { Â Â Â int data; Â Â Â Node next; Â Â Â Â Â Â Â Node( int data) { Â Â Â Â Â Â Â this .data = data; Â Â Â Â Â Â Â this .next = null ; Â Â Â }} Â class LinkedList { Â Â Â Node head; Â Â Â Â Â Â Â LinkedList() { Â Â Â Â Â Â Â head = null ; Â Â Â } Â Â Â Â Â Â Â void insertAtBeginning ( int data) { Â Â Â Â Â Â Â Node newNode = new Node (data); Â Â Â Â Â Â Â newNode.next = head; Â Â Â Â Â Â Â head = newNode; Â Â Â }}Solution
The code provided is a valid implementation of a singly linked list with an insertion operation at the beginning. Here's why A is the correct answer:
- Node class defines a single node with data and next reference.
- LinkedList class manages the list and allows for the insertion of a new node at the beginning by setting the new node's next to the current head and updating the head to point to the new node.
Which one of the statement is incorrect regarding Velunachiar?
I. She was born as a Princess of Ramanathapuram
II. Her husband was Mu...
10% of 5 and 5% of 10 add upto
As per the Economic Survey of India 2021-22 report (as per advance estimates), the service sector has contributed nearly ____of India’s 2021-22 GDP.
Which saint composed 'Sant Gun Sagar' and 'Naam-Maala' ?
In 2018, which committee has submitted its report on Special Economic Zones to the Ministry of Commerce and Industry?
Which of the following banks are public sector banks?
A. Canara bank
B. Bank of Baroda
C. Central bank of India
D. Induslnd bank
E. RBL bank
Which one of the following is the longest river in Asia which passes through major part of East Asia?
The famous king Pulakeshin I belonged to which of the following dynasty?
(I) : The old leaders of the congress were conscious of the ruinous economic policy of the British Government.
(I) : Dadabhai Naoroji, Ramesh ...
The word "TRANSTAN" is associated with