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]
4 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]4 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
Your child has broken the RJ-45 port of your laptop by sticking clay into it and there are no wireless networks available in you
sesenic [268]

Answer:

آمل أن يساعد هذا Purchase and use a USB to RJ-45 adapter-yes

fiber_manual_record Enable NIC teaming to increase your bandwidth

Explanation:

67.185.94.80

6 0
3 years ago
How much data can a flash drive store?​
zzz [600]

Answer:

depends on which flash drive

Explanation:

32GB-1000 photos

6 0
3 years ago
Read 2 more answers
What are the six things you will learn this week on Scratch?
notka56 [123]

Answer:

1 You can learn to draw

2 You can learn to code

3 You can learn to make a thumbnail

4 You can learn how to follow yourself

5 You can learn  to remix your own projects

6 You can learn how to make a featured project you've never shared

Explanation:

8 0
3 years ago
What is the critical path?
Natali [406]

Answer:

Option C. The path from start to finish that passes through all the tasks that are critical to completing the project in the shortest amount of time

is the correct answer.

Explanation:

  • Critical path is the term used in Project management.
  • It can be known by determining the longest stretch for dependent activities and the time required for them to complete.
  • A method known as "critical path method" is used for Project modelling.
  • All types of projects including aerospace, software projects, engineering or plant maintenance need Critical method analysis for the modeling of project and estimation.

I hope it will help you!

3 0
3 years ago
I need help with this work
lisabon 2012 [21]

Answer:

B. Balanced depending and the type of questions

5 0
3 years ago
Other questions:
  • When working with data returned from a query wizard, refreshing a query occasionally produces undesired results. if this occurs,
    9·1 answer
  • The Joint Photographic Experts Group developed the ___________ graphic format.
    12·2 answers
  • The fact that the speed of a vehicle is lower than the prescribed limits shall relieve the driver from the duty to decrease spee
    11·2 answers
  • This inventor made their own fortune. They had little to no help in become one of the first black millionaires. They invented a
    9·1 answer
  • A microphone plugs into what type of connector
    5·2 answers
  • Are you concerned that strangers may have access to the personal information you share on social media platforms? Why or why not
    10·1 answer
  • Which of the following is one aspect of gaming that goes relatively unnoticed but
    10·1 answer
  • What is the purpose of exploring data?
    6·2 answers
  • Please help it’s timed
    11·1 answer
  • Who do we need more in the world? Computer technicians, or electric technicians and why.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!