1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Tema [17]
3 years ago
11

Write a function that implements another stack function, peek. Peek returns the value of the first element on the stack without

removing the element from the stack. Peek should also do underflow error checking. (Why is overflow error checking unnecessary
Computers and Technology
1 answer:
devlian [24]3 years ago
3 0

Answer:

See explaination

Explanation:

StackExample.java

public class StackExample<T> {

private final static int DEFAULT_CAPACITY = 100;

private int top;

private T[] stack = (T[])(new Object[DEFAULT_CAPACITY]);

/**

* Returns a reference to the element at the top of this stack.

* The element is not removed from the stack.

* atreturn element on top of stack

* atthrows EmptyCollectionException if stack is empty

*/

public T peek() throws EmptyCollectionException

{

if (isEmpty())

throw new EmptyCollectionException("stack");

return stack[top-1];

}

/**

* Returns true if this stack is empty and false otherwise.

* atreturn true if this stack is empty

*/

public boolean isEmpty()

{

return top < 0;

}

}

//please replace "at" with the at symbol

Note:

peek() method will always pick the first element from stack. While calling peek() method when stack is empty then it will throw stack underflow error. Since peek() method will always look for first element ffrom stack there is no chance for overflow of stack. So overflow error checking is not required. In above program we handled underflow error in peek() method by checking whether stack is an empty or not.

You might be interested in
Why is it better for a CPU to have more than one cache?
Kitty [74]

Explanation:

i think cpu needs to have backup chache units in case of electrical failure

5 0
2 years ago
Read 2 more answers
1. Using a microphone to create an audio file to accompany a message is an example of how data is processed and sent to an outpu
Svetllana [295]

Answer:

I would say true.

5 0
2 years ago
Suppose we have a linearly separable dataset, and we divide the data into training and validation sets. Will a perceptron learne
Sauron [17]

Answer:

Theoretically Yes

Explanation:

The data given is linearly separable. So, the subset of the data will also be linearly separable. And it will pass for all training dataset. However, you should definitely never expect such thing In any real-life problem because the data is noisy, for a bazilion of reasons, so no model is guaranteed to perform perfectly.

3 0
3 years ago
Successful Web sites such as StumbleUpon ( www.stumbleupon) and Digg ( www.digg) use ____ by inviting their visitors to vote on
aliina [53]

Answer:

"Crowdsourcing" is the correct answer for the above question.

Explanation:

  • Crowdsourcing is a term from which any organization advertises the thinks or can get the ideas or solutions for any particular problem.
  • It is a term that refers to the problem to the number of solvers to achieve the result correct and frequent.
  • For example, If anyone wants to prepare the two websites. Then he assigns the works to the number of people and the works done faster with the help of this.
  • The above question states that some websites can be successful with the help of the type of work. They are successful with the help of crowdsourced work. Because it saves time. So the answer is Crowdsourcing.
3 0
3 years ago
The 3rd generation programming language that most students learned when most computers used MS DOS was ___ . It remains a safe p
Diano4ka-milaya [45]

Answer:

Basic

Explanation:

The 3rd generation programming language that most students learned when most computers used MS DOS was basic. It remains a safe programming language for using 3rd party code and provides a coding standard that integrates easily with other programming languages.

7 0
3 years ago
Other questions:
  • 1.
    13·1 answer
  • In this exercise, you are given a phrase and need to return that phrase in all capital letters.
    6·1 answer
  • 1. Zack sees an online contest. He could win $10,000 instantly! On the sign-up form, he enters his name and email address. He is
    15·1 answer
  • What is the use of jacquard loom
    13·2 answers
  • What is a computer OPERATING SYSTEM?
    5·1 answer
  • The picture that graphically represents the items you use in Windows is called a/an <br> ___?
    14·1 answer
  • How is the bootstrap program started?
    6·2 answers
  • What happens to a message when it is deleted?
    5·2 answers
  • An ALGORITHM IS?<br> PLEASE HELP
    14·1 answer
  • A financially stable person is able to:
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!