Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
11th Edition
ISBN: 9780134671710
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, Vector, or Stack.
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
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?
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.
Using java, write an easier version of a linked list with only a couple of the normal linked list functions and the ability to generate and utilize a list of ints. The data type of the connection to the following node can be just Node, and the data element can be just an int. You will need a reference like (Java) or either a reference to the first node, as well as one to the last node.
(Answer the following questions)
1) Create a method or function that accepts an integer, constructs a node with that integer as its data value, and then includes the node to the end of the list. If the new node is the first one, this function will also need to update the reference to the first node. This function will need to update the reference to the final node. Consider how to insert the new node following the previous last node, and keep in mind that the next reference for the list's last node should be null.
2) Create a different method or function that iteratively explores the list, printing…
Chapter 20 Solutions
Introduction to Java Programming and Data Structures: Brief Version (11th Global 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
- 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…arrow_forwardJavaarrow_forwardFor C++ in a doubly linked list, how would you print the list in reverse?? void double LL::printReverse()arrow_forward
- write a code in modules and also with main class to implement the operation on linked list.. (searching , traversing , updating , and inserting.) insertion will be In empty list, In front of list, In the middle of list, at the end of list. The code should be in java language and also with simple coding and explanation.arrow_forwardHelp with c++... please paste indented code plzz and keep output same as givenarrow_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_forward
- Suppose 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_forwardHello 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_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
- Implement a program that creates an unsorted list by using a linked list implemented by yourself. NOT allowed to use LinkedList class or any other classes that offers list functions. It is REQUIRED to use an ItemType class and a NodeType struct to solve this. Use C++! The “data.txt” file has three lines of data 100, 110, 120, 130, 140, 150, 160 100, 130, 160 1@0, 2@3, 3@END You need to create an empty unsorted list add the numbers from the first line to list using putItem() function. Then print all the current keys to command line in one line using printAll(). delete the numbers given by the second line in the list by using deleteItem() function. Then print all the current keys to command line in one line using printAll().. putItem () the numbers in the third line of the data file to the corresponding location in The list. For example, 1@0 means adding number 1 at position 0 of the list. Then print all the current keys to command line in one line…arrow_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