10. Given the following public class IntQueue { private int[] data; private int manyItems; private int...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
10. Given the following public class IntQueue { private int[] data; private int manyItems; private int front; private int rear; public void add(int d) public int remove() } IntQueue s1 = new IntQueue(); q.add(1); q.add(2); q.add(3); System.out.println(s.remove()); Draw the state of the private instance variables of q after the above code b. Complete the add and remove method of the above class. What is the time complexity of each method? c. Suppose that the queue is represented by a singly linked list. public class IntQueue { private IntNode front; private IntNode rear; int manyItems; } Draw the state of the private instance variables of q after the above code d. Complete the add and remove method of the above class in c. What is the time complexity of each method? 11. Suppose you have a stack s that contains (12 3), with 1 being the top-of-stack, and a queue q that is empty. Using no other variables and only the push() and pop() stack operations and the add() and re- move() queue operations, show a sequence of operations that leave the queue q empty and the stack s with each of the following contents. Leave the stack s with the contents (132) with 1 as top-of-stack. 10. Given the following public class IntQueue { private int[] data; private int manyItems; private int front; private int rear; public void add(int d) public int remove() } IntQueue s1 = new IntQueue(); q.add(1); q.add(2); q.add(3); System.out.println(s.remove()); Draw the state of the private instance variables of q after the above code b. Complete the add and remove method of the above class. What is the time complexity of each method? c. Suppose that the queue is represented by a singly linked list. public class IntQueue { private IntNode front; private IntNode rear; int manyItems; } Draw the state of the private instance variables of q after the above code d. Complete the add and remove method of the above class in c. What is the time complexity of each method? 11. Suppose you have a stack s that contains (12 3), with 1 being the top-of-stack, and a queue q that is empty. Using no other variables and only the push() and pop() stack operations and the add() and re- move() queue operations, show a sequence of operations that leave the queue q empty and the stack s with each of the following contents. Leave the stack s with the contents (132) with 1 as top-of-stack.
Expert Answer:
Answer rating: 100% (QA)
a Drawing the state of private instance variables of q after the given code IntQueue q new IntQueue qadd1 qadd2 qadd3 Systemoutprintlnqremove State of the private instance variables of q data 1 2 3 ma... View the full answer
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Posted Date:
Students also viewed these programming questions
-
The second programming project involves writing a program that examines a file of polynomials and determines whether the polynomials in that file are in strictly ascending order using two different...
-
Consider the model Y;jk = + a; + Bi + Yij + Eijk with i = 1,...,I, j= 1,...,J, k = 1,...,K. Show if effects are ~ x. considered random then CY E(CMY)
-
Addison, Inc. makes a single product, an indoor fireplace. Data for last year is as follows: Selling price per fireplace Manufacturing costs: Variable per unit produced: Direct materials Direct labor...
-
Renchen Company, which manufactures steel tubing and casing for automobile production, borrowed $500,000 on January 1 to finance the purchase of a new piece of machinery with new heating technology....
-
Home Team Corporation recently hired Steve Willits as its bookkeeper. Mr. Willits is somewhat inexperienced and has made numerous errors recording daily business transactions. Indicate the effects of...
-
The probabilities that a quality control team will visit \(0,1,2,3\), or 4 production sites on a single day are 0.15,0.22,0.35,0.21, and 0.07. (a) Simulate the inspection team's visits on 30 days....
-
Prior to the start of fiscal 2013, managers of MultiTech hosted a web conference for its shareholders, financial analysts, and members of the financial press. During the conference, the CEO and CFO...
-
A car travels 55 m [E 50 S] before turning and traveling 30 m [E] then traveling 40 m [W 30 S]. The trip takes 70 seconds. a. What is the distance and displacement? b. What is the velocity (net) and...
-
Given the following algorithm (4 points) Algorithm(B) for j2 to length [A] do key A[j] i- j - 1 while i > 0 and A[i] > key do A[i+1] A[i] ii-1 A[i+1] key (a) Describe the function of this algorithm...
-
program # 2 OSpgm2c_4 CGS3767 Operating Systems for IT Professor: Michael Robinson e-mail : michael.robinson@cs.fiu.edu ********* !!!!*** USE THE TOOLS THAT WE HAVE LEARNED IN OUR CLASS ONLY ***!!!!...
-
Under what conditions can an effectuation-based process be more successful than a causation-based process?
-
As CEO of a social media firm (such as Facebook), you have been informed that your firms service will be discontinued in the host country because it allegedly incites social unrest (Egypt and Turkey...
-
What characterizes causation- and effectuation-driven processes, respectively?
-
Discuss the similarities and differences of attitude-based and achievement context models as examples of cognitive motivation theories.
-
Discuss the traits approach to entrepreneurial personality and explain why it fails to properly predict the behaviour of entrepreneurs.
-
Below, n is the sample size, p is the population proportion and p-hat is the sample proportion. Use the Central Limit Theorem and the TI-84 calculator to find the probability. Round the answer to at...
-
Draw two scatterplots, one for which r = 1 and a second for which r = 21.
-
Write a program that displays the following two tables side by side: Kilometers | Kilometers 1.609 3.218 Miles 1. Miles 12.430 15.538 | 25 14.481 37.290 40.398 9. 10 60 | 65 16.090
-
A shipping company uses the following function to calculate the cost (in dollars) of shipping based on the weight of the package (in pounds). Write a program that prompts the user to enter the weight...
-
Write a method to sort a two-dimensional array using the following header: public static void sort(int m[][]) The method performs a primary sort on rows and a secondary sort on columns. For example,...
-
Debate: Survey feedback can be a problematic OD technique because it permits people who are affected by organizational policies to generate data that speak against those policies.
-
You have been charged with staffing and organizing an R&D group in a new high-tech firm. What will you do to ensure that the group is innovative?
-
Discuss: The best organizational structure to generate innovative ideas might not be the best structure to implement those ideas.
Study smarter with the SolutionInn App