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
Question
Chapter 19.5, Problem 19.5.2CP
Program Plan Intro
Sort method in “Listing 19.4”:
The sort method in “Listing 19.4” used sort the values of generic type “E[]” as parameter and returns the sorted values.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
You will reverse your student ID by the linked list of Struct in C!!!!
Input: 1->2->3->4->5->NULL
Output: 5->4->3->2->1->NULL
Create a linked list and insert your student ID elementwise to the list.
Reverse the linked list and printout the result.
Hint: You can use additional pointers to reverse the linked list. You can also use a stack and then simply assign the element to the stack and it will be reversed. Linked list, Stack, Queue example source code is available on week 7 resources section.
# Create a list of tuplestuples = [("p", 1), ("q", 2), ("r", 3)]# Use enumerate() to iterate over the tuples and print the index and valuefor index, value in enumerate(tuples):print(index, value)This code will print the following output:0 p1 q2 r
Could you try to modify your code to get the output mentioned by you? Also, the output for the above function should be0 ('p', 1)1 ('q', 2)2 ('r', 3) Could you please confirm?
Your solutions can use:• the [] operator to get and set list elements (e.g., lst[i] and lst[i] = a)• the in and not in operators (e.g., a in lst)• the list concatenation operator (e.g., lst1 + lst2)• the list replication operator (e.g., lst * n or n * lst)• Python's built-in len, min and max functions, unless otherwise noted.Your solutions cannot use:• list slicing (e.g., lst[i : j] or (lst[i : j] = t)• the del statement (e.g., del lst[0])• Python's built-in reversed and sorted functions.• any of the Python methods that provide list operations, e.g., sum, append, clear, copy, count, extend, index, insert, pop, remove, reverse and sort• list comprehensions
Automated testing is required
using python language Use the function design recipe to develop a function named Fibonacci_sequence. The function takes an integer n. The function returns a list containing the Fibonacci sequence, up until the nth term. The Fibonacci sequence is defined as Fn = Fn-1 + Fn-2. For example, if n = 6, then the…
Chapter 19 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Ch. 19.2 - Are there any compile errors in (a) and (b)?Ch. 19.2 - Prob. 19.2.2CPCh. 19.2 - Prob. 19.2.3CPCh. 19.3 - Prob. 19.3.1CPCh. 19.3 - Prob. 19.3.2CPCh. 19.3 - Prob. 19.3.3CPCh. 19.3 - Prob. 19.3.4CPCh. 19.4 - Prob. 19.4.1CPCh. 19.4 - Prob. 19.4.2CPCh. 19.5 - Prob. 19.5.1CP
Ch. 19.5 - Prob. 19.5.2CPCh. 19.6 - What is a raw type? Why is a raw type unsafe? Why...Ch. 19.6 - Prob. 19.6.2CPCh. 19.7 - Prob. 19.7.1CPCh. 19.7 - Prob. 19.7.2CPCh. 19.7 - Prob. 19.7.3CPCh. 19.7 - Prob. 19.7.4CPCh. 19.8 - Prob. 19.8.1CPCh. 19.8 - Prob. 19.8.2CPCh. 19.8 - Prob. 19.8.3CPCh. 19.8 - Prob. 19.8.4CPCh. 19.8 - Prob. 19.8.5CPCh. 19.9 - Prob. 19.9.1CPCh. 19.9 - How are the add, multiple, and zero methods...Ch. 19.9 - How are the add, multiple, and zero methods...Ch. 19.9 - What would be wrong if the printResult method is...Ch. 19 - (Revising Listing 19.1) Revise the GenericStack...Ch. 19 - Prob. 19.2PECh. 19 - (Distinct elements in ArrayList) Write the...Ch. 19 - Prob. 19.4PECh. 19 - (Maximum element in an array) Implement the...Ch. 19 - (Maximum element in a two-dimensional array) Write...Ch. 19 - Prob. 19.7PECh. 19 - (Shuffle ArrayList) Write the following method...Ch. 19 - (Sort ArrayList) Write the following method that...Ch. 19 - (Largest element in an ArrayList) Write the...Ch. 19 - Prob. 19.11PE
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
- in python please get_count(aList, item) Returns the number of times item appears in aList. You cannot make any assumptions about the contents of the list. You are not allowed to use any count methods from the Python library. Input list aList A list of elements of any type many item An object of any type Output int Recurrence of item in aList >>> get_count([1,4,3.5,'1',3.5, 9, 1, 4, 2], 1) 2 >>> get_count([1,4,3.5,'1',3.5, 9, 4, 2], 3.5) 2 >>> get_count([1,4,3.5,'1',3.5, 9, 4, 2], 9) 1 >>> get_count([1,4,3.5,'1',3.5, 9, 4, 2], 'a') 0 replace(numList, old, new) Returns a copy of numList with all the occurrences of old replaced by new. The process should not mutate the original list (alter the memory block referenced by numList). You can assume numList is a list of numbers and that old and new are either int or float. You are not allowed to use any replace methods from the Python library. Input list numList A list of numbers int/float old A number…arrow_forwardin python please get_count(aList, item) Returns the number of times item appears in aList. You cannot make any assumptions about the contents of the list. You are not allowed to use any count methods from the Python library. Input list aList A list of elements of any type many item An object of any type Output int Recurrence of item in aList >>> get_count([1,4,3.5,'1',3.5, 9, 1, 4, 2], 1) 2 >>> get_count([1,4,3.5,'1',3.5, 9, 4, 2], 3.5) 2 >>> get_count([1,4,3.5,'1',3.5, 9, 4, 2], 9) 1 >>> get_count([1,4,3.5,'1',3.5, 9, 4, 2], 'a') 0 replace(numList, old, new)Returns a copy of numList with all the occurrences of old replaced by new. The process should not mutate the original list (alter the memory block referenced by numList). You can assume numList is a list of numbers and that old and new are either int or float. You are not allowed to use any replace methods from the Python library. Input list numList A list of numbers int/float old A number…arrow_forwarddef count_types(lst: List[Any]) -> List[int]: """ Given a list <lst> of random types, return the number of occurrences of each type, in the form of a list, in the order that they were first seen. For example, if the input ['str1', 1, 'str2'], the output would be [2, 1], as a string type appears first, and occurs twice in the list. An integer type appears next, and only occurs once in the list. Another example could be [True, 'str1', 1, False, 'str2', True], where the output would be [3, 2, 1], as a boolean type appears first, and occurs three times in the list. A string appears next, and occurs twice in the list. Finally, an integer appears next, and occurs once in the list. """don't use any import, dictionaries, or dictionary methods or try-except statements.arrow_forward
- Define: int findrirstEven (int num [1, int sise); Returns the index location of the first even number of the list; if no even number, returns -1arrow_forwardWhat is stored in list after the following C++ code executes? int list[8];list[0] = 1;list[1] = 2; for (int i = 2; i < 8; i++){list[i] = list[i – 1] * list[i – 2];if (i > 5)list[i] = list[i] - list[i - 1];}arrow_forward@given(lists(integers()), integers ()) def test_append (1st: List, v: int): " "Test that . . . I1111 # TODO: Complete the docstring description and implement this function.arrow_forward
- In python please get_count(aList, item) (1.5 points) Returns the number of times item appears in aList. You cannot make any assumptions about the contents of the list. You are not allowed to use any count methods from the Python library. Input list aList A list of elements of any type many item An object of any type Output int Recurrence of item in aList >>> get_count([1,4,3.5,'1',3.5, 9, 1, 4, 2], 1) 2 >>> get_count([1,4,3.5,'1',3.5, 9, 4, 2], 3.5) 2 >>> get_count([1,4,3.5,'1',3.5, 9, 4, 2], 9) 1 >>> get_count([1,4,3.5,'1',3.5, 9, 4, 2], 'a') 0 replace(numList, old, new) (1.5 points) Returns a copy of numList with all the occurrences of old replaced by new. The process should not mutate the original list (alter the memory block referenced by numList). You can assume numList is a list of numbers and that old and new are either int or float. You are not allowed to use any replace methods from the Python library. Input list numList A list of…arrow_forwardComplete the docstring:from typing import List def count_odds(values: List[List[int]]) -> List[int]: """Return a list of counts of odd numbers in each of the inner lists of values. >>> count_odds([[111, 165, 207]]) [3] >>> count_odds([[1, 2], [8], [5, 6, 7]]) [1, 0, 2] """arrow_forward• Write a method to insert an element at index in a Doubly Linked List data structure and test it. The method receives this list by parameters. *arrow_forward
- def remove_occurences[T](xs:List[T], elem: T, n:Int) : List[A] = {} Using the function above, can you show me how to make a polymorphic function in scala where the program removes elem , n number of times from the list. If n > elem then remove all elem from the list For example: remove_occurences(List(4,5,6,7,4),4,1) -> List(5,6,7,4)remove_occurences(List(4,5,6,7,4),4,2) -> List(5,6,7)remove_occurences(List(4,5,6,7,4),2,2) -> List(4,5,6,7,4)arrow_forward· Write a method to insert an element at index in a Doubly Linked List data structure and test it. The method receives this list by parameters. * in javaarrow_forward6. the grade is under 20 which is outlier, remove it from the array list. 7. Print array list using System.out.println() 8. Use indexOf to print index of 80. 9. Use get function. 10. What is the difference between get and index of? 11. Print the values of the array list using Iterator class. 12.. Delete all the values of the array list using clear function. 13. Print all the values of the array after you execute clear using System.out.println(). what is the result of using clear function? 14. What is the shortcoming of using array List?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