Question

What does the following function do? public T doSomething() throws EmptyCollectionException{       if (isEmpty())             throw new EmptyCollectionException(“St

What does the following function do?

public T doSomething() throws EmptyCollectionException{

      if (isEmpty())

            throw new EmptyCollectionException(“Stack”);

      T result = top.getElement();

       top = top.getNext();

       count--;

       return result;

}

Select one:
a. isEmpty()
b. Push()
c. Pop()
d. Peek()

Homework Answers

Answer #1

c. Pop()

Explanation:
-------------
T result = top.getElement(); this gets the top element
and then    top = top.getNext(); removes the top element of the collection
count--; decreases the size of collection
return result; returns the top element which was removed.
this operation is clearly pop operation.


Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
- implement the Stack ADT using the linked list approach. Use C++ program language #include "StackLinked.h"...
- implement the Stack ADT using the linked list approach. Use C++ program language #include "StackLinked.h" template StackLinked::StackLinked (int maxNumber) { } template StackLinked::StackLinked(const StackLinked& other) { } template StackLinked& StackLinked::operator=(const StackLinked& other) { } template StackLinked::~StackLinked() {    clear(); } template void StackLinked::push(const DataType& newDataItem) throw (logic_error) {    } template DataType StackLinked::pop() throw (logic_error) { } template void StackLinked::clear() {    StackNode* t;    while ( top != NULL)    {        t = top;       ...
I'm having a warning in my visual studio 2019, Can anyone please solve this warning. Severity  ...
I'm having a warning in my visual studio 2019, Can anyone please solve this warning. Severity   Code   Description   Project   File   Line   Suppression State Warning   C6385   Reading invalid data from 'DynamicStack': the readable size is '(unsigned int)*28+4' bytes, but '56' bytes may be read.   Here is the C++ code were I'm having the warning. // Sstack.cpp #include "SStack.h" // Constructor SStack::SStack(int cap) : Capacity(cap), used(0) {    DynamicStack = new string[Capacity]; } // Copy Constructor SStack::SStack(const SStack& s) : Capacity(s.Capacity), used(s.used)...
1.A stack implemented with an array has what performance? Select one: a. O(n3) b. O(n log...
1.A stack implemented with an array has what performance? Select one: a. O(n3) b. O(n log n) c. O(n) d. O(n2) 2. A stack uses the first in first out insertion and deletion method. Select one: True False 3. Match the following stack operations with their meaning. object pop(); boolean isEmpty(); push (object); integer size(); object top(); meanings are: - returns the number of elements stored -just removes the last inserted elements - returns the last inserted elements without removing...
Use the following algorithm: (1) Create three stacks of characters: stk1, stk2, stk3. (2) Read the...
Use the following algorithm: (1) Create three stacks of characters: stk1, stk2, stk3. (2) Read the input infix expression one character at a time and push every character read ( other than ')' ) onto stk1. Do not push the character read if it is ')'. (3) As long as stk1 is not empty, do the following:            Fetch the top character ( call it c ) of stk1 and pop stk1.            if c is an alphabetic character (a-z),...
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class...
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class Food {     static int count;     private String flavor = "sweet";     Food() { count++; }     void setFlavor(String s) { flavor = s; }     String getFlavor() { return flavor; }     static public void main(String[] args) {         Food pepper = new Food();         System.out.println(pepper.getFlavor());     } } a. a class variable b. a constructor c. a local object variable d....
this is the book name. Data Structures and Abstractions with Java 1) Description: The sample programs...
this is the book name. Data Structures and Abstractions with Java 1) Description: The sample programs in Chapter 1 of your textbook are not complete. They are used for illustration purpose only. The implementation of Listing 1-1 on page 39 is explained in Chapter 2. And, in order to see the result of using it, we will need the following set of files: i. BagInteface.java – the specification only. ii. ArrayBag.java – the implementation of BagInerface.java. iii. ArrayBagDemo.java – a...
What Shape does the bid-rent function exhibit if the demand for housing is price-elastic and t...
What Shape does the bid-rent function exhibit if the demand for housing is price-elastic and t = constant (part 1) a) linear b) convex c) concave d) undetermined What Shape does the bid-rent function exhibit if office firms want to be in contact with each other and t = increasing (part 2) a) linear b) convex c) concave d) undetermined What Shape does the bid-rent function exhibit if manufacturing firms do not engage in factor substitution and t = increasing...
Please write the code in Python. Write a program/function in any Object-Oriented programming language that will...
Please write the code in Python. Write a program/function in any Object-Oriented programming language that will implement Queue Abstract Data Type with the following functions/methods.  Any build-in/pre-defined Queue function/library (e.g., java.util.Queue in Java) is NOT allowed to use in your code. push(Element):  insert the input Element (e.g., String or Integer in Java) to the end of the queue. pop(): remove the head element of the queue and print the head element on screen. count():  return the total number of elements in the queue...
Consider the following diagram: If the batchUpdate() method throws a BatchUpdateException, what is printed to the...
Consider the following diagram: If the batchUpdate() method throws a BatchUpdateException, what is printed to the console after the following code is executed? public static void readDatabase() {     try {         DBClass.batchUpdate(); //throws BatchUpdateException     } catch(SQLException) {         System.out.println("SQLException");     }     System.out.println("Continue"); } a. “SQLException” c. “Continue” b. “BatchUpdateException” d. “SQLException” and “Continue”
What is the output of the following Java program? interface Food {     public void printFlavor();...
What is the output of the following Java program? interface Food {     public void printFlavor(); } class Pepper implements Food {     public void printFlavor() { System.out.println("spicy"); } } public class Lunch {     public static void main(String[] args) {        Food pepper = new Pepper();         pepper.printFlavor();     } } Select one: a. spicy b. no output c. the program does not compile d. bland e. bland spicy