Solved

A Stack Based on a Linked List Is Based on the Following

Question 21

Multiple Choice

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 pop() operation is


A) if (top != null)
{
Top = top.next;
String el = top.element;
Return el;
}
Else throw new RuntimeException("Empty Stack") ;
B) if (top != null.
{
String el = top.element;
Top = top.next;
Return el;
}
Else throw new RuntimeException("Empty Stack".;
C) if (top != null.
{
String el = top.element;
Top = null;
Return el;
}
Else throw new RuntimeException("Empty Stack".;
D) return top.element;
Top = top.next;

Correct Answer:

verifed

Verified

Unlock this answer now
Get Access to more Verified Answers free of charge

Related Questions

Unlock this Answer For Free Now!

View this answer and more for free by performing one of the following actions

qr-code

Scan the QR code to install the App and get 2 free unlocks

upload documents

Unlock quizzes for free by uploading documents