Modify the code of Figure 4.18 to implement two stacks sharing the same array, as shown in
Question:
Modify the code of Figure 4.18 to implement two stacks sharing the same array, as shown in Figure 4.20 .
Figure 4.18
Figure 4.20
Transcribed Image Text:
/** Array-based stack implementation */ class AStack implements Stack { private static final int defaultSize = 10; private int maxSize; private int top; private E [] listArray; // Constructors AStack() { this (defaultSize); } @SuppressWarnings ("unchecked") // Generic array allocation AStack (int size) { } public void clear() { top = 0; } public void push (E it) { assert top != maxSize : listArray [top++] = it; } maxSize = size; top = 0; listArray = (E[]) new Object [size]; // Create listArray public E pop() { assert top != 0 "Stack return listArray [--top]; } // Maximum size of stack // Index for top Object // Array holding stack } // Reinitialize stack // Push "it" onto stack "Stack is full"; // Pop top element is empty"; public E topValue () { assert top != 0: "Stack is empty"; return listArray [top-1]; // Return top element public int length() { return top; } // Return length Figure 4.18 Array-based stack class implementation.
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 100% (2 reviews)
java Arraybased stack implementation class AStack implements Stack private static final int defaultS...View the full answer
Answered By
Seema kuldeep
although I don't have an experience of teaching in a particular institute, previously I was an expert on Chegg and I have used to teach my batch mates and also my juniors.
5.00+
1+ Reviews
10+ Question Solved
Related Book For
Practical Introduction To Data Structures And Algorithm Analysis Java Edition
ISBN: 9780136609117
1st Edition
Authors: Clifford A. Shaffer
Question Posted:
Students also viewed these Computer science questions
-
In our first case study on evaluating arithmetic expressions, we used two stacks that held different types of data. In some other applications, we might need two stacks with the same type of data. If...
-
A garment manufacturer produces various types of casual wears, including T-shirts, trousers, and shorts. The company has 24 direct labour employees. All 24 employees are skilled workers to produce...
-
The following additional information is available for the Dr. Ivan and Irene Incisor family from Chapters 1-5. Ivan's grandfather died and left a portfolio of municipal bonds. In 2012, they pay Ivan...
-
Write a report on Home and Automobile: These are two of the most important financial purchases we will make. These decisions, especially housing, will affect much of your ability to meet your...
-
A 1-m3 rigid tank contains 100 kg R-22 at ambient temperature, 15C. A valve on top of the tank is opened, and saturated vapor is throttled to ambient pressure, 100 kPa, and flows to a...
-
Using the distribution of particle translational kinetic energy provided in Problem P33.19, derive an expression for the fraction of molecules that have energy greater than some energy . The rate...
-
This (partial and adapted) advertisement appeared in The Wall Street Journal. A subordinated debenture gives rights to the bondholder that are more restricted than the rights of other bondholders....
-
BrasPetro S.A., a large Brazilian petrochemical company, reported a balance of R$1,594.9 million in Accounts Receivable at the beginning of Year 7 and R$1,497.0 million at the end of Year 7. Its...
-
In order to have more efficient supply chains, when the world becomes your market, what term has been used to describe how intermediaries are often critical to facilitate effective commerce?
-
Modify the array-based queue definition of Figure 4.25 to use a separate Boolean member to keep track of whether the queue is empty, rather than require that one array position remain empty. //...
-
Determine the size of an int variable, a double variable, and a pointer on your computer. (a) Calculate the break-even point, as a function of n, beyond which the array-based list is more space...
-
The following cash flows represent the potential annual savings associated with two different types of production processes, each of which requires an investment of $22,000: Assuming that the...
-
Best Construction completed the following transactions: 2018 February 01: Paid $10,000 cash for used equipment. Best Construction determined that the equipment would last 5 years and that it had no...
-
What are the implications of the actor model, with its emphasis on asynchronous message passing and lightweight concurrency, in the design and development of scalable, fault-tolerant distributed...
-
Calculate the gross profit? Blossom Corporation uses the percentage-of-completion method. At the end of the first year of a $9048000 contract, the following information is available: Costs to date:...
-
The index model has been estimated for stocks A and B with the following results: ra - rf = 0.01 +0.5 (rm -rf) + eA, rB -rf = 0.02 +1.3 (rm -rf)+ eB, OM = 0.25, o(eA) = 0.20, o(eg) = 0.10. The...
-
What is Logistics and its importance in supply chain management?
-
The following income statements and other information are available for the Schneider Company. Required Calculate EVA for 2011. Assume that for purposes of calculating EVA, the company capitalizes...
-
Solve each problem. Find the coordinates of the points of intersection of the line y = 2 and the circle with center at (4, 5) and radius 4.
-
Define a DC component and its effect on digital transmission.
-
Define baseline wandering and its effect on digital transmission.
-
Draw the graph of the NRZ-L scheme using each of the following data streams, assuming that the last signal level has been positive. From the graphs, guess the bandwidth for this scheme using the...
-
(a) Buyer contracts with Manufacturer for the production and delivery of 10,000 Texas Rangers jerseys which will be sold in Buyer's store as part of a special promotion. The contract price is...
-
What is the difference between the first amendment and the wall of separation in the 19th Century and today?
-
a. define empowerment strategies relative to the role of the HRM in Public Administration. b. Share empowerment strategies that would contribute to enhancing training and development skills.
Study smarter with the SolutionInn App