Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Expert Solution & Answer
Chapter 24, Problem 24.5PE
Explanation of Solution
Implementation of GenericQueue using inheritance:
//Define a class Ex24_05
public class Ex24_05 {
//Define the main() function
public static void main(String[] args) {
//Create the generic queue
GenericQueue<String> queue = new
GenericQueue<String>();
//Add the elements into queue
queue.enqueue("Tom");
queue.enqueue("George");
queue.enqueue("Peter");
}
}
//Implement the queue using inheritance
class GenericQueue<E> extends java.util.LinkedList<E> {
//Define the method enqueue()
public void enqueue(E o) {
//Add the elements at the last
this...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
(Please Help. My professor did not teach us any of this and will not answer my emails)
Design a class named Queue for storing integers. Like a stack, a queue holds elements. In a stack, the elements are retreived in a last-in-first-out fashion. In a queue, the elements are retrieved in a first-in-first-out fashion. The class contains:
An int[] data field named elements that stores the int values in the queue
A data field named size that stores the number of elements in the queue
A constructor that creates a Queue object with defult capacity 8
The method enqueue(int v) that adds v into the queue
The method empty () that returns true if the queue is empty
The method getSize() that returns the size of the queue
Fill in the blanks in each of the following statements (CHOOSE ONLY TEN):
5
AP
1. An ---
is created to store information of the method such as the parameters and (0-
local variables specific to a given call of the method, and information about which command in
the body of the method is currently executing.
21. One application of stack is
32. The type of linked list which is contain more memory space is
3. The --------- operation return the top item of stack.
54. The method
used to removes beginning and ending spaces of string
6 5. stack is said underflow when
6. String objects are stored in a special memory area known as
7. Two dimensional array that have a different length is called -----------
A 8. One way to create string object is --------
10 9. is known as
expression.
110. Example of none linear data structures is
12 11. A
is a method that contains a statement that makes a call to itself.
13 12. One application of queue is
JAVA CODE
Learning Objectives: Detailed understanding of the linked list and its implementation. Practice with inorder sorting. Practice with use of Java exceptions. Practice use of generics.
You have been provided with java code for SomeList<T> class. This code is for a general linked list implementation where the elements are not ordered. For this assignment you will modify the code provided to create a SortedList<T> class that will maintain elements in a linked list in ascending order and allow the removal of objects from both the front and back. You will be required to add methods for inserting an object in order (InsertInorder) and removing an object from the front or back. You will write a test program, ListTest, that inserts 25 random integers, between 0 and 100, into the linked list resulting in an in-order list. Your code to remove an object must include the exception NoSuchElementException. Demonstrate your code by displaying the ordered linked list and…
Chapter 24 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Ch. 24.2 - Prob. 24.2.1CPCh. 24.2 - Prob. 24.2.2CPCh. 24.2 - Prob. 24.2.3CPCh. 24.2 - Prob. 24.2.4CPCh. 24.3 - What are the limitations of the array data type?Ch. 24.3 - Prob. 24.3.2CPCh. 24.3 - Prob. 24.3.3CPCh. 24.3 - What is wrong if lines 11 and 12 in Listing 24.2,...Ch. 24.3 - If you change the code in line 33 in Listing 24.2,...Ch. 24.3 - Prob. 24.3.6CP
Ch. 24.3 - Prob. 24.3.7CPCh. 24.4 - Prob. 24.4.1CPCh. 24.4 - Prob. 24.4.2CPCh. 24.4 - Prob. 24.4.3CPCh. 24.4 - Prob. 24.4.4CPCh. 24.4 - Prob. 24.4.5CPCh. 24.4 - Prob. 24.4.7CPCh. 24.4 - Prob. 24.4.8CPCh. 24.4 - Prob. 24.4.9CPCh. 24.4 - Prob. 24.4.10CPCh. 24.5 - Prob. 24.5.1CPCh. 24.5 - Prob. 24.5.2CPCh. 24.5 - Prob. 24.5.3CPCh. 24.6 - What is a priority queue?Ch. 24.6 - Prob. 24.6.2CPCh. 24.6 - Which of the following statements are wrong?...Ch. 24 - (Implement set operations in MyList) The...Ch. 24 - (Implement MyLinkedList) The implementations of...Ch. 24 - (Use the GenericStack class) Write a program that...Ch. 24 - Prob. 24.5PECh. 24 - Prob. 24.6PECh. 24 - (Fibonacci number iterator) Define an iterator...Ch. 24 - (Prime number iterator) Define an iterator class...
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- 3. Define a Pair class using Java Generics framework a. Properties: first, second b. Constructors: Create 2 different constructor with different initialization parameters c. Methods: setFirst(), setSecond(), getFirst(), getSecond(); d. Test Pair class print out the value of Pair instance: i. Define a Pair instance and assign (10,10.1) to the pair; ii. Define a Pair instance and assign (8.2, "ABC") to the pair; iii. Define an array holding[] of Pair class. 1. holding has 100 elements; 2. Assign (int, double) to array by using loop -> (0, 100.0), (1, 99.0), (2, 98.0), ..., (99, 1.0).arrow_forwardUse Python for this question. Also please comment what each line of code means for this question as well: Inheritance (based on 8.38) You MUST use inheritance for this problem. A stack is a sequence container type that, like a queue, supports very restrictive access methods: all insertions and removals are from one end of the stack, typically referred to as the top of the stack. A stack is often referred to as a last-in first-out (LIFO) container because the last item inserted is the first removed. Implement a Stack class using Note that this means you may be able to inherit some of the methods below. Which ones? (Try not writing those and see if it works!) Constructor/_init__ - Can construct either an empty stack, or initialized with a list of items, the first item is at the bottom, the last is at the top. push() – take an item as input and push it on the top of the stack pop() – remove and return the item at the top of the stack isEmpty() – returns True if the stack is empty,…arrow_forwardPlease answer the following question in Python code: Inheritance (based on 8.38) You MUST use inheritance for this problem. A stack is a sequence container type that, like a queue, supports very restrictive access methods: all insertions and removals are from one end of the stack, typically referred to as the top of the stack. A stack is often referred to as a last-in first-out (LIFO) container because the last item inserted is the first removed. Implement a Stack class using Note that this means you may be able to inherit some of the methods below. Which ones? (Try not writing those and see if it works!) Constructor/_init__ - Can construct either an empty stack, or initialized with a list of items, the first item is at the bottom, the last is at the top. push() – take an item as input and push it on the top of the stack pop() – remove and return the item at the top of the stack isEmpty() – returns True if the stack is empty, False otherwise [] – return the item at a given…arrow_forward
- Advance Java Programming Exercise 22.6 (9th Edition) Programming Exercise 20.6 (10th 12th Edition) To enter the values into the linked list, just generate random integers in a loop. Then time the two traversals and display the results (number of entries and traversal times). Prompt the user for the number of entries to generate.arrow_forwardpresentation: Show how to use the diamond operator when creating instances of generic classes in javaarrow_forwardPlease use java code and create a program that completes the task below.arrow_forward
- Practical:1. Write a Java code to illustrate the concept of Set, List and deque. Generate the correct output.2. Give a suitable example of Generic Classes and generate correct output.3. Write a Java code to implement the concept of vector and stack. Generate the correct output.arrow_forwardPlease use Python for this question: 1. Inheritance (based on 8.38) You MUST use inheritance for this problem. A stack is a sequence container type that, like a queue, supports very restrictive access methods: all insertions and removals are from one end of the stack, typically referred to as the top of the stack. A stack is often referred to as a last-in first-out (LIFO) container because the last item inserted is the first removed. Implement a Stack class using inheritance. Note that this means you may be able to inherit some of the methods below: a. Constructor/_init__ - Can construct either an empty stack, or initialized with a list of items, the first item is at the bottom, the last is at the top. b. push() – take an item as input and push it on the top of the stack c. pop() – remove and return the item at the top of the stack d. isEmpty() – returns True if the stack is empty, False otherwise e. [] – return the item at a given location, [0] is at the bottom of the stack f.…arrow_forward(Implement MyMap using open addressing with linear probing) Create a new concrete class that implements MyMap using open addressing with linear probing. For simplicity, use f(key) = key % size as the hash function, where size is the hash-table size. Initially, the hash-table size is 4. The table size is doubled whenever the load factor exceeds the threshold (0.5). Test your new MyHashMap class using the code at https://liveexample.pearsoncmg.com/test/Exercise27_01.txt Class Name: Exercise27_01 If you get a logical or runtime error, please refer https://liveexample.pearsoncmg.com/faq.html MyHashMap.java located here https://liveexample.pearsoncmg.com/html/MyHashMapWithLineNumber.html? IMPORTANT The answer I require, To submit your code to Revel, you must only submit the code enclosed between // BEGIN REVEL SUBMISSION // END REVEL SUBMISSION // BEGIN REVEL SUBMISSION /** Return the first value that matches the specified key */ public V get(K key) { // Perform…arrow_forward
- - Write a Polynomial class that has methods for creating a polynomial, reading and writing a polynomial, and adding a pair of polymomials - In order to add 2 polynomials, traverse both lists, If a particular exponent value is present in either one, it should also be present In the resulting polynomial unless its coefficient is zero. java submit as a text dont use others answers please attach screenshot of output Thank you!!!arrow_forwardWrite the following method in Java: public void reverse() The method will reverse the linked list. Head will point to the last node of the linked list and all the pointers (addresses) will be reversed. The last node (a new head) will point to the second last node and so on. The old head node will become the tail node in the reversed LinkedList. Use the LinkedList class discussed in the video lecture and write the reverse() method in the same class. Test your method in the main method. Following picture depicts the reversal of the LinkedList. NULL Head I V R I ↑ Head > NULLarrow_forwardBreak out the restrictions placed on the stack and its unrestricted counterpart.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education