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
List the general steps that are used to configure a soho router and set up the network
marusya05 [52]
Configure the Internet connection. 

Configure the wireless router. 

Enable NAT. 

Configure DHCP

Secure the SOHO network.
7 0
3 years ago
Why does the position of drawCircle(x, y, r) in the answer choices matter?
Andrei [34K]

Answer:

B and C

Explanation:

xPos and yPos determine the center of the circle, and rad determines the radius of the circle drawn.

It cannot be A because it starts drawing a circle with the center of (4, 1). None of the circles ahve a center at (4, 1). It is B because while it does start at (4, 1), the repeat function adds one to the y and radius. While ti repeats 3 times it ends up drawing all 3 circles. C also works because it starts by drawing the biggest circle and then subtracting the values to make the other two. It cannot be D because in the repeat function it subtracts from the y value and radius too early, it doesn't draw the biggest circle.

6 0
2 years ago
Digital learning can help students who enjoy
mr Goodwill [35]

Answer:

flexibility and independence

Explanation:

6 0
3 years ago
A goal should be___.
Luda [366]

Answer:

D

Explanation:

5 0
3 years ago
Read 2 more answers
Help please im not sure what this means T^T
Vesna [10]

Answer:

14

Explanation:

7 0
3 years ago
Read 2 more answers
Other questions:
  • A group of users can perform certain operations on a shared workbook. Which option helps them to update and track changes in the
    14·1 answer
  • When you arrive at work one morning, your inbox is full of messages complaining of a network slowdown. you collect a capture fro
    12·1 answer
  • Please help me!! 10 Points are waiting!!
    8·1 answer
  • Which would be a responsible use of technology used by victims of cyberbullying?
    12·2 answers
  • If a piece of software designed to run on Windows XP can run on the latest version of Windows, we say the latest version of Wind
    14·1 answer
  • Write out a shorthand version of the border property which will apply border that is 5 px wide, colored in lightgreen, and solid
    9·1 answer
  • Who invented the Bluetooth device​
    12·1 answer
  • Which is a connectionless protocol in the transport layer? What are the small chunks of data called?
    12·2 answers
  • What are some catchy names for computer basics that you would put on a childrens poster?
    9·1 answer
  • Select the correct answer from each drop-down menu.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!