Discussion :: Data Structure MCQs
- Choose the code snippet which inserts a node to the head of the list?
A.
public void insertHead(int data) {
|
B.
public void insertHead(int data) {
|
C.
public void insertHead(int data) {
|
D.
public void insertHead(int data) {
|
Answer : Option A
Explanation :
If the list is empty make the new node as 'head', otherwise traverse the list to the end and make its 'next' pointer point to the new node, set the new node's next point to the current head and make the new node as the head.
Be The First To Comment