(Choose 1 answer)
Suppose we are implementing a stack using a singly linked list where the head of the list is treated as the top of the stack.
A. void push(Object x)
Specify the correct implementation of push() method of the stack. (Choose the most suitable one)
{ Node p = new Node(x);
p.next = head;
head=p;}
B. void push(Object x)
{ Node p = new Node(x);p.next = head;}
C. void push(Object x)
{ Node p = new Node(x);
p.next = null;
head=p;
}
D. void push(Object x)
{ Node p = new Node(x);
p.next = head;head=p.next;
}
Exit (31