answer.
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]
2 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]2 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
a. a large central network that connects other networks in a distance spanning exactly 5 miles. b. a group of personal computers
ki77a [65]

Complete Question:

A local area network is:

Answer:

b. a group of personal computers or terminals located in the same general area and connected by a common cable (communication circuit) so they can exchange information such as a set of rooms, a single building, or a set of well-connected buildings.

Explanation:

A local area network (LAN) refers to a group of personal computers (PCs) or terminals that are located within the same general area and connected by a common network cable (communication circuit), so that they can exchange information from one node of the network to another. A local area network (LAN) is typically used in small or limited areas such as a set of rooms, a single building, school, hospital, or a set of well-connected buildings.

Generally, some of the network devices or equipments used in a local area network (LAN) are an access point, personal computers, a switch, a router, printer, etc.

4 0
1 year ago
When creating a table in the relational database design from an entity in the extended e-r model, the attributes of the entity b
larisa86 [58]
No.  The attributes of the table correspond to columns within the table.  Each unique set of attribute values taken together correspond to table rows.  Sometimes referred to as "records".

8 0
1 year ago
Java languageThe cost to ship a package is a flat fee of 75 cents plus 25 cents per pound.1. Declare a constant named CENTS_PER_
Sophie [7]

Answer:

// Here is code in Java.

// import package

import java.util.*;

// class definition

class Main

{

   // main method of the class

public static void main (String[] args) throws java.lang.Exception

{

    try{

   // variables

    final int CENTS_PER_POUND = 25;

    final int FLAT_FEE_CENTS = 75;

    // Scanner object to read input

   Scanner sr=new Scanner(System.in);

   System.out.print("Enter the shipping weight:");

   // read the input weight

   int shipWeightPounds=sr.nextInt();

   // calculate total cost

  int shipCostCents = (shipWeightPounds * CENTS_PER_POUND) + FLAT_FEE_CENTS;

  // print Weight

  System.out.println("shipping  Weight: " + shipWeightPounds);

  // print flat fee

     System.out.println("flat fee of shipping in cents : " + FLAT_FEE_CENTS);

     // print cents per round

     System.out.println("Cents/pound for shipping: " + CENTS_PER_POUND);

     // print cost of Shipping

    System.out.println("total cost of shipping in cents: " + shipCostCents);

   

   

   }catch(Exception ex){

       return;}

}

}

Explanation:

Declare and initialize two constant variables "CENTS_PER_POUND=25" & "FLAT_FEE_CENTS = 75". Read the input weight from user with the help of Scanner class object. Then  calculate the cost of shipping by multiply weight with cent per pound and add flat fee. Then print each of them.

Output:

Enter the shipping weight:12                                                                                                                                  

shipping  Weight : 12                                                                                                                                        

flat fee of shipping in cents: 75                                                                                                                              

Cents/pound for shipping: 25                                                                                                                                  

total cost of shipping in cents: 375  

8 0
1 year ago
Read 2 more answers
Which command suppresses the visibility of a particular Row or column in a worksheet?
leonid [27]

Answer:

Ctrl+Space is the keyboard shortcut to select an entire column.

Explanation:

When you press the Shift+Space shortcut the first time it will select the entire row within the Table.  Press Shift+Space a second time and it will select the entire row in the worksheet.

The same works for columns.  Ctrl+Space will select the column of data in the Table.  Pressing the keyboard shortcut a second time will include the column header of the Table in the selection.  Pressing Ctrl+Space a third time will select the entire column in the worksheet.

You can select multiple rows or columns by holding Shift and pressing the Arrow Keys multiple times.

4 0
2 years ago
Write a program whose input is two integers and whose output is the two integers swapped. Place the values in an array, where x
Aliun [14]

Answer:

import java.util.Arrays;

public class swap{

   public static void main(String []args){

       int [] arr = {2,4};

       swapValues(arr);

   }

   public static void swapValues(int[] values){

       int temp;

       System.out.println(Arrays.toString(values));

       temp=values[0];

       values[0]=values[1];

       values[1] =temp;

       System.out.println(Arrays.toString(values));

   }

}

Explanation:

In the program above, we created the method swapValues that receives an array of integers as parameters. in the method definition, we created a temp variable that is used to swapp the element at index 0 and index 1. Java's Arrays.to string method is used to print the array before and after the swap.

7 0
2 years ago
Other questions:
  • A chemical found in the synaptic vesicles , which , when released . has an effect on the next cell is called a?
    10·1 answer
  • Writing a program in a language such as c or java is known as _____ the program.
    10·1 answer
  • Mathematical computations by a computer are faster than your quickest mathematical computations because the top speed of a neura
    13·1 answer
  • What level of fault is the following example: North Lake Hospital followed all of the HIPAA policies and procedures for securing
    12·2 answers
  • Identify the articulation site that allows us to nod our head ""yes"".
    13·1 answer
  • [Assembly Language]Extended Subtraction Procedure.Create a procedure named Extended_Sub --(Receives: ESI and EDI point to the tw
    12·1 answer
  • Suppose that a class named ClassA contains a private nonstatic integer named b, a public nonstatic integer named c, and a public
    14·1 answer
  • A program is divided into 3 blocks that are being compiled on 3 parallel computers. Each block takes an Exponential amount of ti
    6·1 answer
  • All organizations need good quality cybersecurity to ensure _____. Select 4 options.
    12·2 answers
  • A local router is configured to limit the bandwidth of guest users connecting to the Internet. Which of the following best expla
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!