A stack and queue can be viewed as a special type of list. Using a stack...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
A stack and queue can be viewed as a special type of list. Using a stack the elements are accessed, inserted, and deleted only from the top of the stack. Whereas, using a queue the elements are inserted into the end (tail) of the queue, and are accessed and deleted from the beginning (head) of the queue. What is the output of the program below that implementing stack and queue (based on this definition)? (6 marks) public class TestStackQueue { public static void main(String[] args) { GenericStack<String> stack = new GenericStack<String> (); stack.push("Hakim"); stack.push("Akim"); stack.push("Aqim"); stack.push("Muhammad"); stack.push("Mohammad"); stack.push("Mohd"); stack.push("Muhd"); System.out.println (stack.pop()); System.out.println(stack.pop()); System.out.println("STACK: " + stack); GenericQueue<String> queue = new GenericQueue<String> (); queue.enqueue ("Hakim"); queue.enqueue ("Akim"); queue.enqueue ("Aqim"); queue.enqueue ("Muhammad"); queue.enqueue ("Mohammad"); queue. enqueue ("Mohd"); queue.enqueue ("Muhd"); System.out.println (queue. dequeue ()); System.out.println (queue.dequeue ()); System.out.println("QUEUE: " + queue); }//end main }//end class A stack and queue can be viewed as a special type of list. Using a stack the elements are accessed, inserted, and deleted only from the top of the stack. Whereas, using a queue the elements are inserted into the end (tail) of the queue, and are accessed and deleted from the beginning (head) of the queue. What is the output of the program below that implementing stack and queue (based on this definition)? (6 marks) public class TestStackQueue { public static void main(String[] args) { GenericStack<String> stack = new GenericStack<String> (); stack.push("Hakim"); stack.push("Akim"); stack.push("Aqim"); stack.push("Muhammad"); stack.push("Mohammad"); stack.push("Mohd"); stack.push("Muhd"); System.out.println (stack.pop()); System.out.println(stack.pop()); System.out.println("STACK: " + stack); GenericQueue<String> queue = new GenericQueue<String> (); queue.enqueue ("Hakim"); queue.enqueue ("Akim"); queue.enqueue ("Aqim"); queue.enqueue ("Muhammad"); queue.enqueue ("Mohammad"); queue. enqueue ("Mohd"); queue.enqueue ("Muhd"); System.out.println (queue. dequeue ()); System.out.println (queue.dequeue ()); System.out.println("QUEUE: " + queue); }//end main }//end class
Expert Answer:
Answer rating: 100% (QA)
First lets define the GenericStack and GenericQueue classes and their respective push pop enqueue and dequeue methods according to the provided definition class GenericStack private List elements publ... View the full answer
Related Book For
Java How To Program Early Objects
ISBN: 9780134743356
11th Edition
Authors: Paul Deitel, Harvey Deitel
Posted Date:
Students also viewed these algorithms questions
-
How does MariaDB leverage optimizer enhancements such as Cost-Based Optimization (CBO), Index Condition Pushdown (ICP), and Histogram-Based Statistics to improve query execution efficiency and plan...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
12. For a piece of material, the steady state flow of material across its thickness is 0.250 x 10 kg/m-hr. If the concentrationon the high side of the material is 1.85 kg/m and is 0.06 kg/m on the...
-
Repeat the previous problem, but with variable heat capacities.
-
A mixture of three amino aids is separated by gel electrophoresis. The three amino acids are glycine, valine and phenylalanine (Figure 27.14). a. The electrophoresis is carried out in a buffer...
-
Axial dispersion in channel flow. Consider the pressure-driven laminar flow in a channel of height \(2 h\). Derive the following formula for the axial dispersion coefficient: \[D_{\mathrm{E}}=\frac{2...
-
The following is the unadjusted trial balance for Rainbow Lodge Ltd. at its year end, May 31, 2015. The company adjusts its accounts monthly. Additional information: 1. An annual insurance policy was...
-
As Kelly gained approval for the project plan now, he has to get the security clearance from the IT administrator to access the site. To gain security clearance, you are required to write an email to...
-
Conduct a Pareto analysis for the number of minutes that flights are late in the accompanying data. Interpret the results. E Click the icon to view the Atlanta Airline Data. Conduct a Pareto analysis...
-
9. Notes may be issued a. To creditor's to temporarily satisfy an account payablecreated earlier. b. When borrowing money. c. When assets are purchased. d. All of these choices are correct. 10. The...
-
Under the Age Discrimination in Employment Act, a plaintiff must show that the unlawful discrimination was the reason for an adverse employment action. (True/False)
-
A person can insure anything in which they have an insurable interest. (True/False)
-
Hermosa sells her boat to Chris and Nora. Chris and Nora are not married. The contract of sale says that each of the buyers has a right of survivorship in the boat. Chris and Nora own the boat as a....
-
A mechanics lien always involves real property, and an artisans lien always involves personal property. (True/False)
-
Brent, Jon, and Kenzie owned Kenzies Lemonade Corp., which made and sold fruit drinks. Each owned one-third of the shares of the corporate stock, and each was a director. A disagreement arose over...
-
A and B formed a partnership. The following are their contributions A B Cash P 160,000 - Accounts receivable 100,000 - Inventory 160,000 - Land P 120,000 Building 250,000 Total 420,000 370,000 Note...
-
In Exercises 516, find the focus and directrix of the parabola with the given equation. Then graph the parabola. y 2 = 4x
-
What does the following program do? // Exercise ANS: : SomeClass.java public class SomeClass { public static String someMethod(int[] array2, int x) if (x < array2.length) { return String.format(...
-
Based on the dangling-else discussion in Exercise 4.27, state the output for each of the following code segments when x is 9 and y is 11 and when x is 11 and y is 9. We eliminated the indentation...
-
Fill in the blanks in each of the following statements: a. Lambda expressions implement . b. With iteration the library determines how to access all the elements in a col- lection to perform a task....
-
What is the genetic code? a. The relationship between a three-base codon sequence and an amino acid or the end of translation b. The entire base sequence of an mRNA molecule c. The entire sequence...
-
Lets suppose a researcher mixed together nucleotides with the following percentages of bases: 30% G, 30% C, and 40% A. If RNA was made via polynucleotide phosphorylase, what percentage of the codons...
-
If a tRNA has an anticodon with the sequence 3-GAC-5, which amino acid does it carry? a. Aspartic acid c. Leucine b. Valine d. Glutamine
Study smarter with the SolutionInn App