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 20.9, Problem 20.9.3CP
Explanation of Solution
“Yes”, the TestCollection.java program can be compiled and run when changing the occurrence of ArrayList to LinkedList,
Reason:
- The LinkedList class implements the Deque interface.
- The Deque interface extends the Queue interface. So the LinkedList class able to create a queue and process the insertion and deletion operation from both ends.
- The Queue interface extends the Collection interface. So, the LinkedList class is subclass of Collection interface...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
What is the best way to implement a stack or a queue so that it can hold an arbitrary number of elements? Select one: a. Using an array, and throwing an exception when the stack or queue is full. b. By creating a bigger array when the stack or queue is full, and copying the elements from the original array. c. Using linked lists to store the collection of elements.
Please give a detailed answer and code examples for all of the questions below.What is an array and linked list?What the difference between array and List?Difference between ArrayList and Arrays in Java?
You may do this assignment using either Java or C++. Do *not use the JDK LinkedList class
or any linked list library!
A linked list consists of zero or more nodes, which each contain one item of data and a link
(Java reference, C++ pointer or reference) to the next node, if there is one.
Linked List code is usually generic, so that you can use it to create a list of Strings, Students,
Doubles, etc. For this assignment, you will write a simplified version of linked list that only
can be used to create and use a list of ints and that has only a few of the functions typical of
linked lists. The data element can be just an int, and the data type of the link to the next
node can be just Node.
You will need a reference (Java) or either a reference or a pointer (C++) to the first node, as
well as one to the last node.
Write a method/function that takes an in, creates a node with that int as its data value, and
adds the node to the end of the list. This function will need to update the…
Chapter 20 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Ch. 20.2 - Prob. 20.2.1CPCh. 20.2 - Prob. 20.2.2CPCh. 20.2 - Prob. 20.2.3CPCh. 20.2 - Prob. 20.2.4CPCh. 20.2 - Prob. 20.2.5CPCh. 20.3 - Prob. 20.3.1CPCh. 20.3 - Prob. 20.3.2CPCh. 20.3 - Prob. 20.3.3CPCh. 20.3 - Prob. 20.3.4CPCh. 20.4 - Prob. 20.4.1CP
Ch. 20.4 - Prob. 20.4.2CPCh. 20.5 - Prob. 20.5.1CPCh. 20.5 - Suppose list1 is a list that contains the strings...Ch. 20.5 - Prob. 20.5.3CPCh. 20.5 - Prob. 20.5.4CPCh. 20.5 - Prob. 20.5.5CPCh. 20.6 - Prob. 20.6.1CPCh. 20.6 - Prob. 20.6.2CPCh. 20.6 - Write a lambda expression to create a comparator...Ch. 20.6 - Prob. 20.6.4CPCh. 20.6 - Write a statement that sorts an array of Point2D...Ch. 20.6 - Write a statement that sorts an ArrayList of...Ch. 20.6 - Write a statement that sorts a two-dimensional...Ch. 20.6 - Write a statement that sorts a two-dimensional...Ch. 20.7 - Are all the methods in the Collections class...Ch. 20.7 - Prob. 20.7.2CPCh. 20.7 - Show the output of the following code: import...Ch. 20.7 - Prob. 20.7.4CPCh. 20.7 - Prob. 20.7.5CPCh. 20.7 - Prob. 20.7.6CPCh. 20.8 - Prob. 20.8.1CPCh. 20.8 - Prob. 20.8.2CPCh. 20.8 - Prob. 20.8.3CPCh. 20.9 - How do you create an instance of Vector? How do...Ch. 20.9 - How do you create an instance of Stack? How do you...Ch. 20.9 - Prob. 20.9.3CPCh. 20.10 - Prob. 20.10.1CPCh. 20.10 - Prob. 20.10.2CPCh. 20.10 - Prob. 20.10.3CPCh. 20.11 - Can the EvaluateExpression program evaluate the...Ch. 20.11 - Prob. 20.11.2CPCh. 20.11 - If you enter an expression "4 + 5 5 5", the...Ch. 20 - (Display words in ascending alphabetical order)...Ch. 20 - (Store numbers in a linked list) Write a program...Ch. 20 - (Guessing the capitals) Rewrite Programming...Ch. 20 - (Sort points in a plane) Write a program that...Ch. 20 - (Combine colliding bouncing balls) The example in...Ch. 20 - (Game: lottery) Revise Programming Exercise 3.15...Ch. 20 - Prob. 20.9PECh. 20 - Prob. 20.10PECh. 20 - (Match grouping symbols) A Java program contains...Ch. 20 - Prob. 20.12PECh. 20 - Prob. 20.14PECh. 20 - Prob. 20.16PECh. 20 - (Directory size) Listing 18.10,...Ch. 20 - Prob. 20.20PECh. 20 - (Nonrecursive Tower of Hanoi) Implement the...Ch. 20 - Evaluate expression Modify Listing 20.12,...
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
- Write a Reverse Polish Notation (RPN) calculator in Java. Write a Stack class for doubles: constructor and push, pop, empty, peek functions. Use an array implementation for the stack (or a linked list if you did this before class on 3/5). If you want, you can limit the stack size to ten (HP only had three on their first attempt!), but in that case you should make your push do nothing if the stack is full. Most modern stack implementations have no arbitrary size limit. The pop and peek methods should throw an exception if they are called on an empty stack (see code for this below). Write a RPN class: constructor (takes a String expression, e.g. "3 4 5 + *") and an evaluate method which returns a double ("3 4 5 + *" would evaluate to (4+5)*3=27). Write a RPNCalculator class: main method with whatever accouterments you see fit. Allow the user to type in an expression, then evaluate it and repeat until they say quit.arrow_forwardHey, Please fill in the missing code needed for the three sum implementation in Java. Please provide code comments aswell. Thanks. Code required to fill in is in the do something area. import java.util.Arrays;import java.util.List;public class ThreeSum {private static final List<String> filePaths = new ArrayList<>();static {filePaths.add("resources/1Kints.txt");filePaths.add("resources/2Kints.txt");filePaths.add("resources/4Kints.txt");filePaths.add("resources/8Kints.txt");filePaths.add("resources/16Kints.txt");}public static void main(final String[] args) {for (final String path : filePaths) {// do something}}public static int threeSumA(final int[] array) {final int length = array.length;int count = 0;for (int i = 0; i < length; i++) {for (int j = i+1; j < length; j++) {for (int k = j + 1; k < length; k++) {if (array[i] + array[j] + array[k] == 0) {count++;}}}}return count;}public static int threeSumB(final int[] array) {final int length =…arrow_forwardSuppose you have created a new class: SortedLinkedList. This class is derived from LinkedList (single links). You are asked to overload the method Insert. The method Insert will no longer take in a parameter position, this is because now Insert will place the element in the correct position such that the list is always sorted. Write the C++ code for the implementation of that Insert method.arrow_forward
- Hello i need help with this code. this is the problem: In Listing 11.10, MyStack is implemented using composition. Define a new stack class that extends ArrayList.Draw the UML diagram for the classes then implement MyStack. Write a test pro-gram that prompts the user to enter five strings and displays them in reverse order. and this was the solution i got import java.util.Scanner; public class Exercise11_10 { public static void main(String[] args) { Scanner input = new Scanner(System.in); MyStack stack = new MyStack(); for (int i = 0; i < 5; i++) stack.push(input.nextLine()); System.out.println(stack.getSize() + " strings are: "); while (!stack.isEmpty()) System.out.println(stack.pop()); }} // MyStack.java: Implementing a stack using inheritanceclass MyStack extends java.util.ArrayList<Object> { public boolean isEmpty() { return super.isEmpty(); } public int getSize() { return size(); } public Object peek() { return…arrow_forwardJava: Write a method/programme that will take a generic linked list and make a palindrome of the list. In a seperate test programme the user can add any elements to the generic list and then this list must be made a palindrome. The output should be the original list with the palindrome list added to this list.arrow_forwardWhat are the similarities and differences between a -HashSet and an ArrayList? Use the descriptions of Set, HashSet, List, and -ArrayList in the library documentation to find out, because HashSet is a -special case of a Set, and ArrayList is a special case of a Listarrow_forward
- Give two reasons why would you use an ArrayList instead of an array to implement a stack or a queuearrow_forwardCan someone please show me how to insert a Node into a Circular Linked List that keeps an alphabetic order? The node holds a string and the language c++. Please use classes and show a lot of comments. Thank youarrow_forwardUse java and indent the code properly.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