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
Solnce55 [7]
3 years ago
14

Let s be a stack. Consider the following program:

Computers and Technology
1 answer:
yawa3891 [41]3 years ago
7 0

Answer:

Hi

In the first scenario we have

S = []

then:

S=[1],

S=[2,1]

S=[3,2,1]

S=[2,1]

S=[4,2,1]

S=[2,1]

S=[1]

So when it's call the method peek to S, X will be assigned 1

Explanation:

Stack is a linear data structure which follows a particular order in which the operations are performed. The order may be LIFO(Last In First Out). There are many real-life examples of a stack. Consider an example of plates stacked over one another in the canteen. (Taken from wikipedia)

- The method <em>push</em> is to put the element on the top of the stack

- The method <em>pop</em> is take out the top element of the stack

- The method <em>peek</em> is to see what is the top element of the stack

You might be interested in
How does the browser display the same webpage whether you enter the URL or the IP address in the address bar? What system transl
ASHA 777 [7]
Your browser references a DNS server that translates a word or phrase of a url into an IP and then tells your browser what the IP address is so the browser can navigate to it. My google is not working atm sorry but you can google "what does DNS stand forin networking" and get an answer.
8 0
4 years ago
This program will store roster and rating information for a soccer team. Coaches rate players during tryouts to ensure a balance
Simora [160]

Answer:

// Scanner class is imported to allow program receive user input

import java.util.Scanner;

// class is defined

public class PlayerRoster {

   // main method that begin program execution

  public static void main(String[] args) {

   // Scanner object scan is defined

     Scanner scan = new Scanner(System.in);

   // multi-dimensional array to hold the jersey number and rating

     int[][] players = new int[5][2];

   // boolean flag to keep program alive

     boolean keepAlive = true;

   // the user input is declared as input of type char

     char input;

     

   // for loop that receive 5 player jersey number and ratings

   // it assigns the received input to the already initialized array

     for (int i = 0; i < 5; i++) {

        System.out.println("Enter player " + (i+1) + "'s jersey number: ");

        players[i][0] = scan.nextInt();

        System.out.println("Enter player " + (i+1) + "'s rating: ");

        players[i][1] = scan.nextInt();

        System.out.println();

     }

   // a blank line is printed

     System.out.println();

   // a method is called to display players array

     outputRoster(players, 0);

     

   // while the flag is true

   // display the Menu by calling the outputMenu method

     while (keepAlive) {

        outputMenu();

       // user input is assigned to input

        input = scan.next().charAt(0);

       //  if user input is 'q' then program will quit

        if (input == 'q') {

           keepAlive = false;

           break;

        }

       //  else if input is o, then outputRoaster is called to display players

        else if (input == 'o') {

           outputRoster(players, 0);

        }

       //  else if input is 'u', then user is allowed to edit a player rating

        else if (input == 'u') {

           System.out.println("Enter a jersey number: ");

           int jerseyNum = scan.nextInt();

           System.out.println("Enter a new rating for the player: ");

           int newRating = scan.nextInt();

           for (int l = 0; l < 5; l++) {

              if (players[l][0] == jerseyNum) {

                 players[l][1] = newRating;

              }

           }

        }

       //  else if input is 'a', user is allowed to add a new rating

        else if (input == 'a') {

           System.out.println("Enter a rating: ");

           int rating = scan.nextInt();

           outputRoster(players, rating);

        }

        // else if input is 'r', user is allowed to replace a player

        else if (input == 'r') {

           System.out.println("Enter a jersey number: ");

           int jerseyNum = scan.nextInt();

           boolean exists = true;

           for (int l = 0; l < 5; l++) {

              if (players[l][0] == jerseyNum) {

                 System.out.println("Enter a new jersey number: ");

                 players[l][0] = scan.nextInt();

                 System.out.println("Enter a rating for the new player: ");

                 players[l][1] = scan.nextInt();

              }

           }

           

        }

     }

     

     return;

  }

 

// this method take two parameters, players and min

// it then returns player with ratings greater than min

  public static void outputRoster(int[][] players, int min) {

     System.out.println(((min>0) ? ("ABOVE " + min) : ("ROSTER")));

     int item = 1;

     for (int[] player : players) {

        if (player[1] > min) {

           System.out.println("Player " + item + " -- Jersey number: " + player[0] + ", Rating: " + player[1]);

        }

        item++;

     }

     System.out.println();

  }

 

// outputMenu method to display the program menu

  public static void outputMenu() {

     System.out.println("MENU");

     System.out.println("u - Update player rating");

     System.out.println("a - Output players above a rating");

     System.out.println("r - Replace player");

     System.out.println("o - Output roster");

     System.out.println("q - Quit\n");

     System.out.println("Choose an option: ");  

  }

}

Explanation:

The program is written in Java and it is well commented.                                          

5 0
3 years ago
Lisa and her husband would like to buy a house soon. She continuously pays bills late. How do her actions affect her and others?
stiks02 [169]
Well actually it affects her credit. Home owners would not want to sell a house to someone who doesn't pay bills on time. It shows he/she is unreliable

3 0
3 years ago
Read 2 more answers
Which of the following policy guidelines specifies the restrictions on user access
Levart [38]

The policy guidelines that specifies such restrictions on user access can be referred to as: A. Least privilege.

<h3>What is the Least Privilege Principle?</h3>

The least privilege principle can be described as a concept in information security and policy guidelines that gives a user minimum permission or levels of access that they are needed to execute a tasks.

Therefore, the policy guidelines that specifies such restrictions on user access can be referred to as: A. Least privilege.

Learn more about least privilege on:

brainly.com/question/4365850

6 0
3 years ago
True or false The content and form of digital text is static
Leona [35]
I wore haute you using Brainly.

False. Nothing is lacking in movement.

That was was pretty difficult, had to do some research for that one. So it may not be to correct one.
6 0
3 years ago
Read 2 more answers
Other questions:
  • Theresa is a certified teacher. She just had a baby and would like to stay home, but still wants to teach. Which career would be
    11·2 answers
  • When federal courts are evaluating digital evidence from computer-generated records, what exception is applied to hearsay?'
    13·1 answer
  • What keyboard shortcut keys selects cell A1
    12·1 answer
  • Walking paths across the part is represented by the equation why equals -4x - 6​
    9·1 answer
  • Investigations involving the preservation, identification, extraction, documentation, and interpretation of computer media for e
    12·1 answer
  • What is a palindrome?
    13·1 answer
  • If you embed a Word table into PowerPoint, what happens when you make edits to the embedded data? A. Edits made to embedded data
    12·1 answer
  • Practice with CSS. a. Write the CSS for an HTML selector footer with the following characteristics: a light-blue background colo
    11·1 answer
  • What is output if month = 11 and day = 14?
    13·2 answers
  • A line graph is a great tool for showing changes over time. Why is a line graph better than other graphs at showing this type of
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!