Write a method shift that takes a stack of integers

Assignment Help JAVA Programming
Reference no: EM13704517

Question: Write a method shift that takes a stack of integers and an integer n as parameters and that shifts n values from the bottom of the stack to the top of the stack.

For case: if a variable called s stores the following sequence of values: bottom [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] top

If we make the call shift(s, 6); the method shifts the six values at the bottom of the stack to the top of the stack and leaves the other values in the same order producing: bottom [7, 8, 9, 10, 6, 5, 4, 3, 2, 1] top

Notice that the value that was at the bottom of the stack is now at the top, the value that was second from the bottom is now second from the top, the value that was third from the bottom is now third from the top, and so on, and that the four values not involved in the shift are now at the bottom of the stack in their original order.

If s had stored these values instead: bottom [7, 23, -7, 0, 22, -8, 4, 5] top

If we make the subsequent call: shift(s, 3); then s should store these values after the call: bottom [0, 22, -8, 4, 5, -7, 23, 7] top

You are to use one queue as auxiliary storage to solve this problem. You may presume that the parameter n is >= 0 and not larger than the number of elements in the stack.

Reference no: EM13704517

Questions Cloud

Create an employee class : Create an Employee class. Items to include as data members are employee number, name, data of hire, job description, department, and monthly salary. The class is often used to display an alphabetical listing of all employs.
Calculates the cutoff frequency in a simple rc circuit : Write a simple Java application which calculates the cutoff frequency in a simple RC circuit.
Provide a regular expression that shows the set of strings : Provide a regular expression that shows the set of strings over {a, b} thatcontain at least one b if its length is at least four.
Calculates the cutoff frequency in a simple rc circuit : Write a simple Java application which calculates the cutoff frequency in a simple RC circuit. Your application should ask the user to enter the capacitor and resistor values of the circuit. You must use the JOptionPane class to collect the user's ..
Write a method shift that takes a stack of integers : Write a method shift that takes a stack of integers and an integer n as parameters and that shifts n values from the bottom of the stack to the top of the stack.
Write the buttonhandler inner class : The output string should say something like this: "The RC time constant for resistance 1000 and capacitance .000001 is 0.001 seconds." Clicking one of the buttons generates the event which causes the program to do the selected calculation and upda..
Explain in words a linear-time algorithm : The max subsequence product problem for an array a = a1,a2,...,an of integers is the problem of determining the largest product E(summation)k=1(bottom) j(top) ak formed by a subsequence of a.
Use counting sort to sort an array : State the difficulty in attempting to use counting sort to sort an array of n floating-point numbers from the continuous interval [0,1].
Distributed file system : What problems/issues are involved with a distributed file system (DFS) with regards to data consistency?

Reviews

Write a Review

JAVA Programming Questions & Answers

  Demonstrate knowledge of design patterns

Your software should make use of the concepts outlined at the start of the assignment brief above. Think about where you can employ appropriate design patterns and other techniques.

  Calls the function readarray to read data into the array

Write a function void readArray(int arr[], int length) to read in length many values into the array arr.

  Carl has implemented two programs

Carl picks 20 random names and finds that P1 sorts them faster than P2. "We're using P1!" exclaims Carl. Why are you hesitant to commit?

  A regular polygon is an n-sided polygon

A regular polygon is an n-sided polygon in which all sides are of the same length and all angles have the same degree(i.e the polygon is both equilateral and equiangular).

  Tasks for an array of integers

Write array methods that carry out the subsequent tasks for an array of integers by completing the ArrayMethods class below. Test each method.

  Consider an array of integers

Consider an array of integers as below: int[] a = {5, 2, -4, 3, 0, -5, 7, 11, 6, 13} Complete the method named count(int[] a) in the class Count. The method should return the number of positive numbers in the array

  Explain where the following method invocations

Explain where the following method invocations are most likely to be found in a program for dealing with census data organized using the Model, View, Controller (MVC) design pattern. Choices are zero or more of Model, View, and Controller. Be sure to..

  You have to design and implement a simple and small email

helo i need your help in java assignment. i need solution asap. i have seen the same question on your website and even

  Compare swing java gui components to awt components

Compare Swing Java GUI components to AWT components. Explain at least one way the components are similar and at least one way they are different.

  Determines if the input string is a valid lock combination

Write a Java program that satisfies the given requirement - Prompts the user to input exactly nine characters, which constitute a valid lock combination.

  Create your own date class

You are to write a program that determines the day of the week for New Year's Day in the year 3000. To do this, you must create your own date class (MyDate) and use the following interface and main program:

  World data app

Prepare WorldDataApp project. It implements the NameIndex portion, including creating it in SetupProgram, and searching, viewing and updating it in UserApp program.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd