A stack based on a linked list is based on the following code
Class Node{
String element;
Node next;
Node(String el,Node n) {
Element = el;
Next = n;
}
}
Node top = null;
The code for implementing the String peek() operation is
A) String temp = top.element;
If (temp != null) return temp;
Else
Throw new RuntimeException("Empty Stack") ;
B) if (top != null.
Return top.element;
Else return top.next;
C) if (top != null.
Return top.element
Else
Throw new RuntimeException("Empty Stack".;
D) if (top != null.
Return top;
Correct Answer:
Verified
Q17: Consider a class that uses the following
Q18: The stack pop operation
A) removes all items
Q19: In an array-based implementation of a stack,an
Q20: The stack peek operation
A) checks a stack
Q21: A stack based on a linked list
Q23: A queue based on a linked list
Q24: In a queue implementation that uses an
Q25: A stack based on a linked list
Q26: Consider a class that uses the following
Q27: In an implementation of a stack based
Unlock this Answer For Free Now!
View this answer and more for free by performing one of the following actions
Scan the QR code to install the App and get 2 free unlocks
Unlock quizzes for free by uploading documents